Is there a way I can get historic performance data of various alerts in Nagios as json/xml?

1.7k views Asked by At

I am looking to get performance data of various alerts setup in my Nagios Core/XI. I think it is stored in RRDs. Are there ways I can get access to it?

1

There are 1 answers

8
Nagios Support On

If you're using Nagios XI you can get this data a few different ways.

If you're using XI 5 or later, then the easiest way that springs to mind is the API. Log in to your XI server as an administrator, navigate to 'Help' menu, then select 'Objects Reference' on the left hand side navigation and find 'GET objects/rrdexport' from the Objects Reference navigation box (or just scroll down to near the bottom).

An example curl might look like this:

curl -XGET "http://nagiosxi/nagiosxi/api/v1/objects/rrdexport?apikey=YOURAPIKEY&pretty=1&host_name=localhost"

Your response should look something like:

{
    "meta": {
        "start": "1453838100",
        "step": "300",
        "end": "1453838400",
        "rows": "2",
        "columns": "4",
        "legend": {
            "entry": [
                "rta",
                "pl",
                "rtmax",
                "rtmin"
            ]
        }
    },
    "data": {
        "row": [
            {
                "t": "1453838100",
                "v": [
                    "6.0373333333e-03",
                    "0.0000000000e+00",
                    "1.7536000000e-02",
                    "3.0000000000e-03"
                ]
            },
            {
                "t": "1453838400",
                "v": [
                    "6.0000000000e-03",
                    "0.0000000000e+00",
                    "1.7037333333e-02",
                    "3.0000000000e-03"
                ]
            }
        ]
    }
}

BUT WAIT, THERE IS ANOTHER WAY

This way will work no matter what version you're on, and would actually work if you were processing performance data with NPCD on a Core system as well.

Log in to your server via ssh or console and get your butt over to the /usr/local/nagios/share/perfdata directory. From here we're going to use the localhost object as an example..

$ cd /usr/local/nagios/share/perfdata/
$ ls
localhost
$ cd localhost/
$ ls
Current_Load.rrd   Current_Users.xml  HTTP.rrd  PING.xml            SSH.rrd         Swap_Usage.xml
Current_Load.xml   _HOST_.rrd         HTTP.xml  Root_Partition.rrd  SSH.xml         Total_Processes.rrd
Current_Users.rrd  _HOST_.xml         PING.rrd  Root_Partition.xml  Swap_Usage.rrd  Total_Processes.xml
$ rrdtool dump _HOST_.rrd

Once you run the rrdtool dump command, there is going to be an awful lot of output, so I keep that as an exercise for you, the reader ;)

If you're trying to automate something of some kind, then you should note that the xml files contain meta data for the rrd files and could potentially be useful to parse first.

Also, if you're anything like me, you love reading technical manuals. Here is a great one to read: RRDTool documentation

Hope this helped!