I don't have all the answers here, but here is what I can comment on:
1) You could assume that the reported state of an object at the time of an ack on said object applied to that object's state at that time. This is not perfect, but it should allow you to derive which acks went with which states.
2) This is true, though you could either assume a previous state or ignore time ranges without states in nagios_statehistory.
3) Relation to what?
My sql-fu is failing me today, but you could run a combination of the following queries to get close. The first will output the ack table with a join on object_id (where name1=<hostname>):
Code: Select all
echo "select entry_time,state,author_name,comment_data,name1,name2 from nagios.nagios_acknowledgements inner join nagios.nagios_objects on nagios.nagios_acknowledgements.object_id=nagios.nagios_objects.object_id where name1='gent';" | mysql -t -pnagiosxi
This should output a table similar to:
Code: Select all
+---------------------+-------+----------------------+------------------------------+-------+------------------+
| entry_time | state | author_name | comment_data | name1 | name2 |
+---------------------+-------+----------------------+------------------------------+-------+------------------+
| 2012-11-26 05:07:21 | 1 | Nagios Administrator | Problem is acknowledged | gent | Memory Usage |
| 2012-11-26 05:07:21 | 1 | Nagios Administrator | Problem is acknowledged | gent | / Disk Usage |
| 2013-02-18 13:48:04 | 2 | Andyb | Problem is acknowledged | gent | CPU Stats |
| 2013-02-18 13:48:04 | 2 | Andyb | Problem is acknowledged | gent | Swap Usage |
| 2013-02-18 13:48:04 | 2 | Andyb | Problem is acknowledged | gent | Memory Usage |
| 2013-02-18 13:48:04 | 2 | Andyb | Problem is acknowledged | gent | Users |
| 2013-02-18 13:48:04 | 2 | Andyb | Problem is acknowledged | gent | / Disk Usage |
| 2013-02-18 13:48:04 | 2 | Andyb | Problem is acknowledged | gent | Total Processes |
| 2013-02-18 13:48:04 | 2 | Andyb | Problem is acknowledged | gent | Load |
| 2013-05-10 14:33:50 | 1 | Nagios Administrator | Problem is acknowledged | gent | NULL |
| 2013-05-10 14:33:50 | 2 | Nagios Administrator | Problem is acknowledged | gent | Ping |
| 2013-05-10 14:33:50 | 2 | Nagios Administrator | Problem is acknowledged | gent | Total Processes |
| 2013-05-10 14:33:50 | 2 | Nagios Administrator | Problem is acknowledged | gent | CPU Stats |
| 2013-05-10 14:33:50 | 2 | Nagios Administrator | Problem is acknowledged | gent | Swap Usage |
| 2013-05-10 14:33:50 | 2 | Nagios Administrator | Problem is acknowledged | gent | Memory Usage |
| 2013-05-10 14:33:50 | 2 | Nagios Administrator | Problem is acknowledged | gent | Users |
| 2013-05-10 14:33:50 | 2 | Nagios Administrator | Problem is acknowledged | gent | / Disk Usage |
| 2013-05-10 14:33:50 | 2 | Nagios Administrator | Problem is acknowledged | gent | Load |
| 2013-05-10 14:33:50 | 3 | Nagios Administrator | Problem is acknowledged | gent | super ping check |
| 2013-05-10 14:34:17 | 2 | Nagios Administrator | Problem is acknowledged | gent | Swap Usage |
| 2013-06-21 11:58:33 | 3 | andy | Some Acknowledgement Comment | gent | Load |
| 2013-06-21 11:59:17 | 3 | andy | Some Acknowledgement Comment | gent | Load |
+---------------------+-------+----------------------+------------------------------+-------+------------------+
And then run a second query on the entry_time for each ack to output the nearest (in the past) state change from nagios_statehistory(where name1=<hostname>, name2=<service description>, and state_time=<the ack entry_time> - I used the last entry from the query results above):
Code: Select all
echo "select name1,state_time,output,state from nagios.nagios_statehistory inner join nagios.nagios_objects on nagios.nagios_statehistory.object_id=nagios.nagios_objects.object_id where name1='gent' and name2='Load' and state_time <= '2013-06-21 11:59:17' order by state_time desc LIMIT 1;" | mysql -t -pnagiosxi
This query should output something similar to:
Code: Select all
+-------+-------+---------------------+---------------------------------------------------------------------------------------------+-------+
| name1 | name2 | state_time | output | state |
+-------+-------+---------------------+---------------------------------------------------------------------------------------------+-------+
| gent | Load | 2013-06-04 23:18:17 | CHECK_NRPE: Received 0 bytes from daemon. Check the remote server logs for error messages. | 3 |
+-------+-------+---------------------+---------------------------------------------------------------------------------------------+-------+
Notice how the state is the same.
The iteration through the ack's entry_time(s) may require a stored procedure, a script, or a query written by someone with more sql-fu than myself.
The queries above may need to be altered a bit for services, but the principle is the same.