Monday 26 September 2011

Check_MK clustered services

The documentation for check is old!
Following the clustered services docs won't work, so what you have to do is this:

1/ Define your clusters in main.mk, Don't define it in a separate clustered_services.mk file
2/ Define clusters like so:

clusters.update({
'lon-stasql02.vm.prod|win|mssql': ['lon-sta02a.vm.prod','lon-sta02b.vm.prod'],
})

3/ Defline clustered services like so:
clustered_services_of ['lon-stasql02.vm.prod'] = [( ALL_HOSTS,[ 'fs_D:/', 'fs_E:/','fs_F:/','fs_G:/','fs_H:/','fs_I:/','fs_J:/','fs_K:/','fs_L:/','fs_M:/','fs_N:/','fs_O:/','fs_P:/','fs_Q:/','fs_X:/','fs_Y:/','fs_Z:/', 'proc_SQL Agent', 'service_MSSQLSERVER']),]

4/ Then when inventorying, you MUST inventory all nodes in one shot, otherwise it will not add them to the cluster.

check_mk -uII lon-sta02a.vm.pro lon-sta02b.vm.prod
check_mk -O

5/ Note that this must all be defined in your main.mk
Done!

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
}

Tuesday 6 September 2011

Vim: How to delete the first n characters from every line or region


deletes the first 5 characters of every line

:%s/^.\{5}//gic


Alternatively:

:v
visual mode, then
0
then CTRL +V for visual block
tada!

Monday 5 September 2011

kexec and how to do a cold reboot without editing the kexec default file

just issue the coldreboot command to reboot without using kexec :D

That binary is part of the kexec-tools package