Email when Warning, Script when Critical?


Hi All,
I am new here and a newbie in Nagios.

I am trying to get this escalation thing working, but have to reckon that I am a bit struggling…
Here is what I have in my service_escalations.cfg :

define serviceescalation
        host_name               HP2600nClientServices
        service_description     Check_HP_Col_Toner_Level
        first_notification      3
        last_notification       4
        notification_interval   30
        contact_groups          nagiosadmin,ithelpdesk

IS this correct ?
I have a service that’s checking the state of the ink a printer. If the status is ‘Warning’, the system sends an email. Easy…

But… I have no idea if it possible to run a script (php) when the status is Critical… Can this be done ?
What I want to do is to insert data in a MsSQL db to raise a ticket in a helpdesk system.

Would be very gratefull to get some help here…

Thank you


Your escalation definition will work for every service state (warning, critical, unknown or recovery) and it will send only 3rd and 4th email to nagiosadmin and ithelpdesk. All other email will go to default recepient you have defined in service definition of Check_HP_Col_Toner_Level.

If you want to send an email only to nagiosadmin when the service is in warning state and run a script when the service is critical then you’ll have to take another approach. It could be done, not the way it meant to be but it can be achieved.
Create one contact that has a command that runs the script under notification command, like this:

define contact{ contact_name script_contact alias ticket_script_contact service_notification_period 24x7 host_notification_period 24x7 service_notification_options c host_notification_options d,u,r service_notification_commands ticket_script_command host_notification_commands host-notify-by-email email pager }
And put it in some contactgroup:

define contactgroup{ contactgroup_name script_contact_group alias script_ticket_group members script_contact }
Then define the command that would issue the script:

# 'ticket_script command definition' define command{ command_name ticket_script_command command_line /path/to/your/script/ }
With these you will have a contact upon whom will only in Critical service state (take a look at the service_notification_options c variable that defines that) be issued a service_notification_commands ticket_script which we have defined to run your script.

After that is set and done, you will have to define another service escalation but only for Critical states that would escalate the problem to the contact defined above (not really escalate the problem to the contact but run the script, 'cause we’ve defined it that way):

define serviceescalation{ host_name HP2600nClientServices service_description Check_HP_Col_Toner_Level contact_groups script_contact_group first_notification 1 last_notification 1 notification_interval 1 escalation_period 24x7 escalation_options c }

With this you will get first email (read first executing of the script, which will also be the last cause I assume you don’t want to create more then one ticket for a problem) only when the service goes to Critical state.

If you like that then it is it. If you don’t want ithelpdesk to be notified with Warning notifications then you could remove the service escalation you’ve defined and define the contacts only through the service definition, but that is of your choice and configurable to your needs.