In previous posts of this series, we have gone through how leexportpy works, how it is configured and currently supported services for transforming and pushing Logentries Query API data to other systems. When it comes to creating a new service for leexportpy, the core of leexportpy is quite dynamic and flexible. Placing your new service file that conforms to the requirements in the ‘services’ directory of leexportpy package is all that you need.
As leexportpy is designed to be run on premise, you can implement your own service in a way that it will synchronize your Logentries data with your own private services such as your databases, messaging systems, workflow managers, notification services and so on.
Creating a new service
There are a few rules to be followed for a new service to be discovered and run successfully by the core leexportpy code at runtime.
For the sake of this example, let’s assume that we want to create a new service called (as it is written in configuration file): “example”
Service file location
All new service files should be located under ‘services’ directory of leexportpy. Core leexportpy code scans this directory at the beginning of execution and loads them into its internal service map to be used later if there is any configured job for this service in the configuration file.
Service file name
Service file name should have the suffix of _service.py to be successfully loaded by leexportpy at start up. Following the assumption we made at the beginning, the file name of this service should be: example_service.py
Class name should be the capitalized name of our service and underscores removed if any. For our example: ExampleService.
Your new service class should extend Service class in the main namespace and init of parent Service class should be called:
Methods to implement:
There are three methods to implement for each service. These methods were created to address separate concerns regarding transforming and pushing Logentries REST data to 3rd parties. After implementing these methods as a part of the service class, core leexportpy will be able to utilize these implementations and run the search for you.
This is the method where we need transform our response. Based on the type of the Logentries Query API response, such as timeseries or statistics, the response should be manipulated and returned with a structure that our 3rd party will be able to process. For the sake of this example, we are calculating the average of our calculated values in the timeseries or group response and we are logging a warning if the response is not a statistics response. We can always use static methods of Response classes to determine what type of response we received.
_push method is the interface interacting with external endpoints. Any use of connections, file operations or similar external system interactions should be handled here.
For the ExampleService we are building, we will be making a post request to an http inspector with the payload we got from _transform method. Note that we need a ‘push_url’ in our destination part of our search configuration.
This is the method called by core leexportpy to trigger _transform and _push operations for the specific search configuration. _push method should be supplied with the returned object of the _transform method. Additional business logic may be implemented between _transform and _push calls i.e.: deciding to push the payload or not.
As we have described the structure and the usage of leexportpy configuration file in previous posts, we need to define our service in Services section and supply it with a service specific ‘api_key’ if any. In our example, there will be no api_key associated with the service, so we will just define the service to enable it.
And in our search configuration we should include the push_url of our service and define the service type as ‘example’ which is the name of our service. In our example, we are supplying it with a temporary http request inspector URL:
That’s it! All you need to do is follow these rules for creating a new service in leexportpy. The core module of leexportpy will do the rest for you.
Leexportpy gives you the ability to push your Logentries Query data to your services in a scheduled and automated manner. Keeping your services up to date with Logentries data can be a great gain for your organization considering the countless different queries you can run against your log via Logentries REST Query API.
Ready to export your log data to 3rd party services? Sign up for a free 30 day trial of Logentries today, get started.