Page 1 of 1

MariadDB Query for Total alert generated from last WEEK/MONT

Posted: Wed Jun 14, 2017 2:14 am
by prasadt
Hello Team,

As we are getting total alert information from the Nagios Core Dashboard, Can we get that total number of alerts from the Mariadb query.

We want that data in our application portal to show how many alerts generated every WEEK/MONTH/DAY.

For doing this we need mariadb Query to generate weekly monthly total alert like it is showing in the attachment.

Can you please check and let me know the Query.

Regards,
Manoj Namdev

Re: MariadDB Query for Total alert generated from last WEEK/

Posted: Wed Jun 14, 2017 8:46 am
by mcapra
I'm a bit confused. Nagios Core doesn't have a MariaDB back-end. Unless you're referring to NagiosQL? Or Nagios XI?
We want that data in our application portal to show how many alerts generated every WEEK/MONTH/DAY.
If you wanted to do this programatically, I think the JSON Query Generator is probably the best route.

Re: MariadDB Query for Total alert generated from last WEEK/

Posted: Wed Jun 14, 2017 10:28 am
by scottwilkerson
@mcapra is correct, this data isn't in a DB in Core by default

Re: MariadDB Query for Total alert generated from last WEEK/

Posted: Wed Jun 14, 2017 11:29 am
by prasadt
Thanks team,

Its great help you guys are genius.

Can you just tell me how i can run JSON Query means fields to get desired output.

I want to count weekly hard alerts from the nagios core server.. I am little bit confused in date format and some other fields.

Please help me.

Thanks for your prompt support also

Re: MariadDB Query for Total alert generated from last WEEK/

Posted: Wed Jun 14, 2017 11:34 am
by prasadt
Specifically confused with Date Format and how i can keep "start time" and "end time"

Re: MariadDB Query for Total alert generated from last WEEK/

Posted: Wed Jun 14, 2017 12:04 pm
by mcapra
prasadt wrote: I want to count
2017_06_14_11_59_14_JSON_Query_Generator.png
prasadt wrote:weekly
2017_06_14_12_00_38_JSON_Query_Generator.png
2017_06_14_12_00_38_JSON_Query_Generator.png (9.97 KiB) Viewed 2437 times
Your "Start Time" and "End Time" will need to be evaluated as unix epochs at the time you make the JSON Query request.
prasadt wrote:hard alerts
2017_06_14_12_03_28_JSON_Query_Generator.png
2017_06_14_12_03_28_JSON_Query_Generator.png (3.61 KiB) Viewed 2437 times
Which creates this request:

Code: Select all

http://10.35.6.50/nagios/cgi-bin/archivejson.cgi?query=alertcount&statetypes=hard&starttime=1493657796&endtime=1497459396
Which returns this JSON structure:

Code: Select all

{
    "format_version": 0,
    "result": {
        "query_time": 1497459542000,
        "cgi": "archivejson.cgi",
        "user": "nagiosadmin",
        "query": "alertcount",
        "query_status": "released",
        "program_start": 1497368308000,
        "last_data_update": 1497459181000,
        "type_code": 0,
        "type_text": "Success",
        "message": ""
    },
    "data": {
        "selectors": {
            "starttime": 1493657796000,
            "endtime": 1497459396000,
            "statetypes": 1
        },
        "count": 155
    }
}

Re: MariadDB Query for Total alert generated from last WEEK/

Posted: Wed Jun 14, 2017 12:42 pm
by prasadt
Thanks Mcapra,

Perfect Thanks a lot you saved my life.

I Got what i was looking and i tried from every wrong place but in only 1 days you guys have cracked this even i can say in just some minutes.

Thanks a lot for simplify this and given me in such a perfect query.

Have a nice DAY :-)

You can please close this ticket.


Regards,
Manoj Namdev