Sending PowerStore logs to Syslog
In this article we will explore how to get the logs from a DellEMC PowerStore array to a Syslog server. For this purpose we will use the PowerStore’s REST API, which is a great piece of engineering and a joy to work with as a developer. If you want to learn more about the PowerStore REST API I strongly recommend you quickly skim through the 2 articles I have written about the REST API.
- Part 1 - http://anzpiper.blogspot.com/2020/08/intro-to-dellemc-powerstore-rest-api.html
- Part 2 - http://anzpiper.blogspot.com/2020/08/powerstore-rest-api-best-practices.html
In particular the second article demonstrates the capabilities of the REST API query language. This is a great feature I will use heavily in the last section so I strongly recommend you read that one at least
As a side note, Syslog was developed in 1980. So this year it has turn 40 years old! That is a long time by any measure ... many of my colleagues were not even born in 1980. But in the technology scale it looks even scarier. 1980 is closer in time to the ENIAC than to Kubernetes which is like the Pleistocene in human terms 😃.
For easier navigation, this blog article has been divided into three sections:
- Understand the types of Logs in PowerStore
- Introduction to Logstash
- Sending PowerStore logs to a Syslog server
If you can't wait to see all of this in action you can watch the video now. Otherwise read on!
1 - Understand the logs in PowerStore
PowerStore exposes 4 sources of information that can be considered logs. Depending on the requirement you will take some or all of them:
- Alerts
- Events
- Jobs
- Audit logs
The first 3 can be seen in the GUI under the monitoring tab
The PowerStore API exposes all 4 logs mentioned above as 4
different resources. The following are the API calls to extract the collection
from each of them
- GET /alert
- GET /event
- GET /job
- GET /audit_event
You can use the powerful query features described in my
previous article to tweak the output and extract when you need
Most modern tools support extracting data directly from REST API (Splunk, Solar Winds, Site Scope, …). In fact, chances are that if you are trying to do something smart with the logs you are using a tool that already supports extracting data from a REST API. In this case you don't need Syslog.
As example you can take a look at what my colleague Kyle Prins has done for PowerStore with Splunk. He created a Splunk “app” that can be accessed directly from “Splunkbase”. The app is very comprehensive as it allows you to retrieve data from 87 different API endpoints
2 - Introduction to Logstash
Let’s
quickly introduce Logstash. If you are proficient with Logstash you can skip
ahead to section 3
Once Logstash is installed you need to tell it what to do, ie you need to define the pipelines (what to collect, how to transform it and where to send it to). Logtash requires a "pipeline configuration file" for each pipeline. These files have to have a “.conf” extension and they need to be added to the “/etc/logstash/conf.d/” directory
input {}
filter { # If this section is empty it can be omitted }
output {}
The typical "hello world" for Logstash is to read from “stdin” and write to “stdout”. However we are going to start with something different. Since many logs are usually dumped to files our first basic pipeline will read lines from a file as they are written and create entries into another file. Create a “.conf” file and place in the “conf.d” folder
# "Hello World" pipeline example
input {
file {
path => "/tmp/access_log"
start_position => "beginning"
}
}
output {
file {
path => "/tmp/logstash-test.txt"
}
Now we are ready to start the logstash service. If there are any errors they will show up here
service logstash status -l
Let's test it. I will write some text to the input file and then examine the output file. It should have entries for the changes I made
When dealing with files make sure the right permissions are in place. As you can see below in my implementation Logstash is running as the user “logstash”
So I need to make sure the “logstash” user has access to the input and output files
You can
get an idea of what’s going on in the background by checking the log file. If there are any errors you will see them here too
tail /var/log/logstash/logstash-plain.log
I am going to stop it for now
service logstash stop
- logstash-codec-*
- logstash-filter-*
- logstash-input-*
- logstash-output-*
3 - Sending PowerStore logs to a Syslog server
3.1 - Extracting the logs from PowerStore
- Can we retrieve the data with Logstash?
- Is there an “input plugin" for Logstash that allows us to query the REST API?
For example we can get the entries in the “audit_event” log like this (please replace 10.1.1.1 with the actual IP address of your PowerStore)
curl -k -u admin:P@sw0rdZ --request GET https://10.1.1.1/api/rest/audit_event
The “-u” parameter is used to specify username and password. Remember this user has to have enough rights to access the log in question. The “user” and the “password” need to be separated by “:”
curl -k --header 'Authorization: Basic YWRtaW46UEBzdzByZFo='
--request GET https://10.1.1.1/api/rest/audit_event
The string that follows the “--header” parameter is the Base64 encoding of the “username:password” string. You can create this with a “basic authentication header generator” online or with another tool like Postman. Put the username and password in the “Authorization” tab
And then in the “Headers” tab you can see the resulting string
The “--request" parameter is specifying the GET method and the URL for “audit_event” logs. As we covered in the PowerStore REST API best practices article, the API tries to be as efficient as possible and only returns the “id” of each object. So we need to be explicit if we want more information (or use the “*” wildcard). Additionally it would be good to sort the entries by showing the newest first.
When we put this into a pipeline configuration file, it will look like this
exec {
command => "curl -k --header 'Authorization: Basic YWRtaW46UEBzdzByZFo=' --request GET https://10.1.1.1/api/rest/audit_event?select=id,type,resource_type,resource_action,message_code,message_arguments,timestamp?order=timestamp.desc"
schedule => "0 * * * *"
}
}
output {
file {
path => "/tmp/logstash-test.txt"
}
As you can see the “exec” plugin includes a very handy cron-like scheduler. In this case Logstash will retrieve the 100 (by default) most recent entries in the audit_event log every hour. Feel free to configure the URL to suit your needs based on the PowerStore REST API best practices.
3.2 - Sending the logs to Syslog
- Is there an output plugin to send logs to Syslog?
3.3 – Additional considerations
- Firstly, we could wrap the cURL command into a shell script
- The shell script could start by calculating the previous interval's timestamp in the format that the REST API expects
- We then send a request to the API to retrieve entries with a timestamp greater than the previous interval
exec {
command => "sh -c /tmp/getev5mins.sh
schedule => "*/5 * * * *"
}
}
output {
syslog {
host => "127.0.0.1"
port => 514
protocol => "udp"
rfc => "rfc3164"
}
If one wants to use this method but want minimize the chances of missing log entries, the "TSTART" definition could be adjusted to calculate a timestamp further back in time, ex: "now -10 minute.
Again no responsibilities from me here. Just take the example and modify it to suit your needs. Ultimately even if the device is the one that sends Syslog messages, some messages might get lost in transit, so there is no perfect solution. One thing to bear in mind is that the logs are not deleted from the array when you extract them via the REST API. So you could always go back and get log entries that you are missing by, for example requesting a specific "id" or even to collect the whole thing from scratch if you need to.
Very nice article,keep updating.
ReplyDeleteThank you.
ServiceNow Online Training
Thanks for your information. very good article.
ReplyDeleteServiceNow Online Training in India
ServiceNow Online Training Hyderabad
Thank you for sharing wonderful information with us to get some idea about that content.
ReplyDeleteServiceNow Training in Ameerpet
ServiceNow Course Online