Wednesday 7 September 2011

Event handlers for Check_mk

main.mk :

all_hosts = [
"myhost|myflag" ,
]

# Enable event handlers for services which prefixes are those seen in the Nagios WI
# Nagios check is identified here as "Legacy_MYSQL" (legacy check)

extra_service_conf["event_handler_enabled"] = [
 ( "1", ALL_HOSTS, ["Legacy_MYSQL"] )
]

# "restart-mysql" and as the event handler command

extra_service_conf["event_handler"] = [
 ( "restart-mysql",ALL_HOSTS, ["Legacy_MYSQL"] )
]

# Define check plugin and event handler command
# See Nagios online documentation examples http://nagios.sourceforge.net/docs/nagioscore/3/en/eventhandlers.html
# and set up according your distro

extra_nagios_conf += r"""

define command{
        command_name    check_mysql_database
        command_line    $USER1$/check_mysql -d '$ARG3$' -H '$HOSTADDRESS$' -u '$ARG1$' -p '$ARG2$'
}

define command{
        command_name    restart-mysql
        command_line    /usr/local/nagios/libexec/eventhandlers/restart-mysql  $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$
        }

"""

legacy_checks = [
  ( ( "check_mysql_database!dbuser!dbpwd!dbname!", "Legacy_MYSQL : Mysql Database dbname", False), [ "myflag" ], ALL_HOSTS ),
]

Set appropriate owner and group to event handler command and then grant permissions to the Nagios user in /etc/sudoers file to perform the system command.

Find new services and reload Nagios : cmk -I && cmk -O

Output Nagios configuration with cmk -N  to check event handler parameters:

define service {
  use                check_mk_default
  host_name            myhost
  service_description        Legacy_MYSQL : Mysql Database dbname
  check_command            check_mysql_database!dbuser!dbpwd!dbname!
  active_checks_enabled        1
  service_groups        +legacy
  event_handler_enabled         1
  event_handler                 restart-mysql
}

No comments:

Post a Comment