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 [email protected]
pager [email protected]
}
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/mysql_ticket_script.sh
}
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.