SQL query to get alerts, and ack info
Posted: Thu Jan 14, 2016 9:16 pm
Ok, this is going to show my ignorance or dim wittedness, or both... Its actually more of an SQL question than Nagios but I'll throw it out there and hope.
I'm working on query to get alerts and ack info from the DB. The 1st query comes back with a short list as desired. The second has repeated info so my joins are wrong. The ack table and servicestatus table aren't directly related.
select name1 Hostname,
current_state Status,
name2 'Service Name',
output Output from nagios_objects, nagios_servicestatus where
object_id = service_object_id
and current_state > 0
and is_active = 1
and nagios_servicestatus.notifications_enabled = 1
order by name1;
select nagios_objects.name1 Hostname,
nagios_servicestatus.current_state Status,
nagios_objects.name2 'Service Name',
nagios_servicestatus.output Output,
nagios_acknowledgements.author_name 'Acked By',
nagios_acknowledgements.comment_data 'Comments'
from nagios_objects, nagios_servicestatus, nagios_acknowledgements
where nagios_objects.object_id = nagios_servicestatus.service_object_id
and nagios_servicestatus.service_object_id = nagios_acknowledgements.object_id
and nagios_servicestatus.current_state > 0
and nagios_objects.is_active = 1
and nagios_servicestatus.notifications_enabled = 1
order by name1;
If it isn't clear, I'm looking for alert info, and ack info in a fairly compact form. Basically, I'm trying to make a report that shows the alert (which is in place), the acker, and the ack comments, which should have the ticket info. All this nonsense is emailed periodically...
You can laugh and point at my SQL as needed.
Thanks!
I'm working on query to get alerts and ack info from the DB. The 1st query comes back with a short list as desired. The second has repeated info so my joins are wrong. The ack table and servicestatus table aren't directly related.
select name1 Hostname,
current_state Status,
name2 'Service Name',
output Output from nagios_objects, nagios_servicestatus where
object_id = service_object_id
and current_state > 0
and is_active = 1
and nagios_servicestatus.notifications_enabled = 1
order by name1;
select nagios_objects.name1 Hostname,
nagios_servicestatus.current_state Status,
nagios_objects.name2 'Service Name',
nagios_servicestatus.output Output,
nagios_acknowledgements.author_name 'Acked By',
nagios_acknowledgements.comment_data 'Comments'
from nagios_objects, nagios_servicestatus, nagios_acknowledgements
where nagios_objects.object_id = nagios_servicestatus.service_object_id
and nagios_servicestatus.service_object_id = nagios_acknowledgements.object_id
and nagios_servicestatus.current_state > 0
and nagios_objects.is_active = 1
and nagios_servicestatus.notifications_enabled = 1
order by name1;
If it isn't clear, I'm looking for alert info, and ack info in a fairly compact form. Basically, I'm trying to make a report that shows the alert (which is in place), the acker, and the ack comments, which should have the ticket info. All this nonsense is emailed periodically...
You can laugh and point at my SQL as needed.
Thanks!