Giter Site home page Giter Site logo

avijeet-singhsfdc / sf-event-monitoring-log-retrieval Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gsa/sf-event-monitoring-log-retrieval

0.0 1.0 0.0 9 KB

Python-based utility to fetch Salesforce Event Monitoring Logs and store them locally for consumption by log monitoring and analytics software.

License: Creative Commons Zero v1.0 Universal

Python 100.00%

sf-event-monitoring-log-retrieval's Introduction

Salesforce Event Monitoring Log Retrieval

A lightweight Python command line utility that fetches Salesforce Event Monitoring Log Files for the purpose of consumption by log management and monitoring software.

Setup

Salesforce Event Monitoring

Setting up Event Monitoring is a two day process. Day one will be setup and on day two you can access actual log files. If you are using Lightning, you will need to switch to classic (as of Winter '17) to turn on Event Monitoring

Steps

  • Go to Setup > Logs > Event Monitoring Setup
  • Click enable
  • Salesforce will start saving logs which can be accessed the next day

Salesforce Connected App

You will need to create a Salesforce Connected app

Steps

  • Go to Setup > Create > Apps
  • Scroll down to Connected Apps, click New
  • Enter the App Name, for instance, Event Monitoring Log Retrieval
  • Enter Basic Information as necessary. Best practice is to use a service account rather than assigning to a specific administrator so that application access is not interrupted if an administrator leaves your team.
  • Callback URL is required but is not necessary for this application. Enter the URL of your salesforce instance.
  • Salesforce Event Monitoring Log Retrieval was built using the following Selected OAuth Scope, Access and Manage Your Data (api). Feel free to create custom permissions as needed.
  • None of the information under Wave App Settings, Custom Connected App Handler, Mobile App Settings, or Canvas App Settings is required
  • Click Save

.env file

  • Copy the .sample.env file and rename to .env.
  • Add site URI, do not include https://
  • Enter user credentials including OAuth Consumer Key and Consumer Secret

Requirements

  • Salesforce Event Monitoring
  • Python v2.7 or greater
  • User with Salesforce API access

Usage

Run Locally

Retrieve logs for a given environment

$ retrieveLogs.py {orgname}
>>Fetching logs from, orgname.cs32.my.salesforce.com

Print debug output to terminal

$ retrieveLogs.py orgname -d
>>Fetching logs from, gsa-red--reddv10dvn.cs32.my.salesforce.com
>>Debug turned on
[TRUNCATED]

Display list of environments stored in .env

$ retrieveLogs.py -e
>>The following environments have credentials stored:
  - orgname1
  - orgname2
  - orgname3
>>You can use one of the sites by entering:

  $ python retrievePackage orgname

Display help

$ python retrieveLogs.py -h
usage: retrieveLogs.py [-h] [-e] [-d] [-l] [-v] [orgName]

Salesforce Event Monitoring Log Retrieval This python script will authenticate
against Salesforce and pull json responses containing api logs that may be
downloaded for consumption by a log processing application. Request responses
are logged in the /logs directory. Each run of this app will generate multiple
requests, those requests are merged into a single log file

positional arguments:
  orgName        enter the org key of the environment contained in .env

optional arguments:
  -h, --help     show this help message and exit
  -e, --env      display list of Salesforce environments contained in the .env
                 file
  -d, --debug    print results of program to terminal
  -l, --log      prints log of http requests to /logs folder
  -v, --verbose  prints full http request and response (status code and
                 headers) log to terminal. **NOTE, this argument prints a lot
                 of information to the terminal

Retrieve basic logs and store in logs/ directory

$ retrieveLogs.py {orgname} -l
>>Fetching logs from, orgname.cs32.my.salesforce.com
>>Logging turned on. File can be found at, logs/20161204-2027.34.log

Retrieve logs and display robust request log information including HTTP requests, response codes, and headers

$ retrieveLogs.py {orgname} -v
>>Fetching logs from, orgname.cs32.my.salesforce.com
[TRUNCATED]

Setup CRON Job

$ crontab -e
0 1 * * * path/to/retrieveLogs.py {orgname}

FAQ and Troubleshooting

500 Response on sa.authenticate()

  • When authenticating, if Salesforce responds with a 500 error but you are able to reach the site via the browser, this is likely due to an outdated OpenSSL library old version of Python. Salesforce requires TLS 1.1 or greater for secure connections. Resolve by upgrading Python and/or OpenSSL.

sf-event-monitoring-log-retrieval's People

Contributors

mvogelgesang avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.