Check MK : Collecter facilement des infos Nagios et étendez ses possibilités

From / Bloc Notes Informatique
Jump to: navigation, search
Check MK

Software version 1.1.12p7
Operating System Debian 6
Website Check MK Website
Last Update 25/05/2012

1 Introduction

Nagios c'est super, ça manque juste de fonctionnalités quelque fois. Alors voici un super addon de la mort qui permet d'extraire des données rapidement et de booster les possibilités (multisites, cluster...).

Nous allons essayer d'aborder ici certaines d'entre elle avec Check MK (alias MK Live Status).

2 Prérequis

Voici les packages nécessaire :

Command aptitude
aptitude install xinetd gcc g++ libc6-dev libstdc++6-dev libapache2-mod-python

3 Installation

3.1 Check MK

On va télécharger la dernière version de check_mk et de l'agent :

Command wget
tar -xzf check_mk-1.1.12p7.tar.gz
cd check_mk-1.1.12p7

Et on lance l'installeur (en gros c'est enter enter enter tout le temps à la windows :

Command ./
> ./ 
               ____ _               _        __  __ _  __               
              / ___| |__   ___  ___| | __   |  \/  | |/ /               
             | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /                
             | |___| | | |  __/ (__|   <    | |  | | . \                
              \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\               
   Check_MK setup                                 Version: 1.1.12p7     
Welcome to Check_MK. This setup will install Check_MK into user defined
directories. If you run this script as root, installation paths below
/usr will be suggested. If you run this script as non-root user paths
in your home directory will be suggested. You may override the default
values or just hit enter to accept them. 
Your answers will be saved to /root/.check_mk_setup.conf and will be 
reused when you run the setup of this or a later version again. Please
delete that file if you want to delete your previous answers.
 * Found running Nagios process, autodetected 17 settings.               
  1) Installation directories of check_mk                                
Executable programs
Directory where to install executable programs such as check_mk itself.
This directory should be in your search path ($PATH). Otherwise you
always have to specify the installation path when calling check_mk:
( default  --> /usr/bin): 
Check_MK configuration
Directory where check_mk looks for its main configuration file 
An example configuration file will be installed there if no is 
present from a previous version.:
( default  --> /etc/check_mk): 
check_mk checks
check_mk's different checks are implemented as small Python scriptlets 
that parse and interpret the various output sections of the agents. Where 
shall those be installed:
( default  --> /usr/share/check_mk/checks): 
check_mk modules
Directory for main componentents of check_mk itself. The setup will
also create a file 'defaults' in that directory that reflects all settings
you are doing right now:
( default  --> /usr/share/check_mk/modules): 
Check_MK Multisite GUI
Directory where Check_mk's Multisite GUI should be installed. Multisite is
an optional replacement for the Nagios GUI, but is also needed for the 
logwatch extension.  That directory should not be
in your WWW document root. A separate apache configuration file will be
installed that maps the directory into your URL schema:
( default  --> /usr/share/check_mk/web): 
Localization dir
Base directory for gettext localization files. Multisite comes prepared for localzation
but does not ship any language per default.:
( default  --> /usr/share/check_mk/locale): 
Some documentation about check_mk will be installed here. Please note,
however, that most of check_mk's documentation is available only online at
( default  --> /usr/share/doc/check_mk): 
check manuals
Directory for manuals for the various checks. The manuals can be viewed 
with check_mk -M <CHECKNAME>:
( default  --> /usr/share/doc/check_mk/checks): 
working directory of check_mk
check_mk will create caches files, automatically created checks and
other files into this directory. The setup will create several subdirectories
and makes them writable by the Nagios process:
( default  --> /var/lib/check_mk): 
agents for operating systems
Agents for various operating systems will be installed here for your 
conveniance. Take them and install them onto your target hosts:
( default  --> /usr/share/check_mk/agents): 
  2) Configuration of Linux/UNIX Agents                                  
extensions for agents
This directory will not be created on the server. It will be hardcoded 
into the Linux and UNIX agents. The agent will look for extensions in the 
subdirectories plugins/ and local/ of that directory:
( default  --> /usr/lib/check_mk_agent): 
configuration dir for agents
This directory will not be created on the server. It will be hardcoded
into the Linux and UNIX agents. The agent will look for its configuration
files here (currently only the logwatch extension needs a configuration file):
( default  --> /etc/check_mk): 
  3) Integration with Nagios                                             
Name of Nagios user
The working directory for check_mk contains several subdirectories
that need to be writable by the Nagios user (which is running check_mk 
in check mode). Please specify the user that should own those 
( autodetected  --> nagios): 
User of Apache process
Check_MK WATO (Web Administration Tool) needs a sudo configuration,
such that Apache can run certain commands as root. If you specify
the correct user of the apache process here, then we can create a valid
sudo configuration for you later::
( autodetected  --> www-data): 
Common group of Nagios+Apache
Check_mk creates files and directories while running as nagios. 
Some of those need to be writable by the user that is running the webserver.
Therefore a group is needed in which both Nagios and the webserver are
members (every valid Nagios installation uses such a group to allow
the web server access to Nagios' command pipe)::
( default  --> nagios): 
Nagios binary
The complete path to the Nagios executable. This is needed by the
option -R/--restart in order to do a configuration check.:
( autodetected  --> /usr/sbin/nagios3): 
Nagios main configuration file
Path to the main configuration file of Nagios. That file is always 
named 'nagios.cfg'. The default path when compiling Nagios yourself
is /usr/local/nagios/etc/nagios.cfg. The path to this file is needed
for the check_mk option -R/--restart:
( autodetected  --> /etc/nagios3/nagios.cfg): 
Nagios object directory
Nagios' object definitions for hosts, services and contacts are
usually stored in various files with the extension .cfg. These files
are located in a directory that is configured in nagios.cfg with the
directive 'cfg_dir'. Please specify the path to that directory 
(If the autodetection can find your configuration
file but does not find at least one cfg_dir directive, then it will
add one to your configuration file for your conveniance):
( autodetected  --> /etc/nagios3/conf.d): 
Nagios startskript
The complete path to the Nagios startskript is used by the option
-R/--restart to restart Nagios.:
( autodetected  --> /etc/init.d/nagios3): 
Nagios command pipe
Complete path to the Nagios command pipe. check_mk needs write access
to this pipe in order to operate:
( default  --> /var/log/nagios/rw/nagios.cmd): 
Check results directory
Complete path to the directory where Nagios stores its check results.
Using that directory instead of the command pipe is faster.:
( autodetected  --> /var/lib/nagios3/spool/checkresults): 
Nagios status file
The web pages of check_mk need to read the file 'status.dat', which is
regularily created by Nagios. The path to that status file is usually
configured in nagios.cfg with the parameter 'status_file'. If
that parameter is missing, a compiled-in default value is used. On
FHS-conforming installations, that file usually is in /var/lib/nagios
or /var/log/nagios. If you've compiled Nagios yourself, that file
might be found below /usr/local/nagios:
( autodetected  --> /var/cache/nagios3/status.dat): 
Path to check_icmp
check_mk ships a Nagios configuration file with several host and
service templates. Some host templates need check_icmp as host check.
That check plugin is contained in the standard Nagios plugins.
Please specify the complete path (dir + filename) of check_icmp:
( autodetected  --> /usr/lib/nagios/plugins/check_icmp): 
  4) Integration with Apache                                             
URL Prefix for Web addons
Usually the Multisite GUI is available at /check_mk/ and PNP4Nagios
is located at /pnp4nagios/. In some cases you might want to define some
prefix in order to be able to run more instances of Nagios on one host.
If you say /test/ here, for example, then Multisite will be located
at /test/check_mk/. Please do not forget the trailing slash.:
( default  --> /): /check_mk
Apache config dir
Check_mk ships several web pages implemented in Python with Apache
mod_python. That module needs an apache configuration section which
will be installed by this setup. Please specify the path to a directory
where Apache reads in configuration files.:
( autodetected  --> /etc/apache2/conf.d): 
HTTP authentication file
Check_mk's web pages should be secured from unauthorized access via
HTTP authenticaion - just as Nagios. The configuration file for Apache
that will be installed contains a valid configuration for HTTP basic
auth. The most conveniant way for you is to use the same user file as
for Nagios. Please enter your htpasswd file to use here:
( default  --> /etc/nagios/htpasswd.users): 
HTTP AuthName
Check_mk's Apache configuration file will need an AuthName. That
string will be displayed to the user when asking for the password.
You should use the same AuthName as for Nagios. Otherwise the user will 
have to log in twice:
( autodetected  --> Nagios Access): 
  5) Integration with PNP4Nagios 0.6                                     
PNP4Nagios templates
Check_MK ships templates for PNP4Nagios for most of its checks.
Those templates make the history graphs look nice. PNP4Nagios
expects such templates in the directory pnp/templates in your
document root for static web pages:
( autodetected  --> /usr/share/pnp4nagios/html/templates): 
RRA config for PNP4Nagios
Check_MK ships RRA configuration files for its checks that 
can be used by PNP when creating the RRDs. Per default, PNP 
creates RRD such that for each variable the minimum, maximum
and average value is stored. Most checks need only one or two
of these aggregations. If you install the Check_MK's RRA config
files into the configuration directory of PNP, PNP will create
RRDs with the minimum of required aggregation and thus save
substantial amount of disk I/O (and space) for RRDs. The default
is to install the configuration into a separate directory but
does not enable them:
( default  --> /usr/share/check_mk/pnp-rraconf): 
  6) Check_MK Livestatus Module                                          
compile livestatus module
This version of Check_mk ships a completely new and experimental
Nagios event broker module that provides direct access to Nagios
internal data structures. This module is called the Check_MK Livestatus
Module. It aims to supersede status.dat and also NDO. Currenty it
is completely experimental and might even crash your Nagios process.
Nevertheless - The Livestatus Module does not only allow extremely
fast access to the status of your services and hosts, it does also
provide live data (which status.dat does not). Also - unlike NDO - 
Livestatus does not cost you even measurable CPU performance, does
not need any disk space and also needs no configuration. 
Please answer 'yes', if you want to compile and integrate the
Livestatus module into your Nagios. You need 'make' and the GNU
C++ compiler installed in order to do this:
( default  --> yes): 
check_mk's binary modules
Directory for architecture dependent binary libraries and plugins
of check_mk:
( default  --> /usr/lib/check_mk): 
Unix socket for Livestatus
The Livestatus Module provides Nagios status data via a unix
socket. This is similar to the Nagios command pipe, but allows
bidirectional communication. Please enter the path to that pipe.
It is recommended to put it into the same directory as Nagios'
command pipe:
( default  --> /var/log/nagios/rw/live): 
Backends for other systems
Directory where to put backends and configuration examples for
other systems. Currently this is only Nagvis, but other might follow
( default  --> /usr/share/check_mk/livestatus): 
You have chosen the following directories: 
 Executable programs             /usr/bin                                
 Check_MK configuration          /etc/check_mk                           
 check_mk checks                 /usr/share/check_mk/checks              
 check_mk modules                /usr/share/check_mk/modules             
 Check_MK Multisite GUI          /usr/share/check_mk/web                 
 Localization dir                /usr/share/check_mk/locale              
 documentation                   /usr/share/doc/check_mk                 
 check manuals                   /usr/share/doc/check_mk/checks          
 working directory of check_mk   /var/lib/check_mk                       
 agents for operating systems    /usr/share/check_mk/agents              
 extensions for agents           /usr/lib/check_mk_agent                 
 configuration dir for agents    /etc/check_mk                           
 Name of Nagios user             nagios                                  
 User of Apache process          www-data                                
 Common group of Nagios+Apache   nagios                                  
 Nagios binary                   /usr/sbin/nagios3                       
 Nagios main configuration file  /etc/nagios3/nagios.cfg                 
 Nagios object directory         /etc/nagios3/conf.d                     
 Nagios startskript              /etc/init.d/nagios3                     
 Nagios command pipe             /var/log/nagios/rw/nagios.cmd           
 Check results directory         /var/lib/nagios3/spool/checkresults     
 Nagios status file              /var/cache/nagios3/status.dat           
 Path to check_icmp              /usr/lib/nagios/plugins/check_icmp      
 URL Prefix for Web addons       /check_mk                               
 Apache config dir               /etc/apache2/conf.d                     
 HTTP authentication file        /etc/nagios/htpasswd.users              
 HTTP AuthName                   Nagios Access                           
 PNP4Nagios templates            /usr/share/pnp4nagios/html/templates    
 RRA config for PNP4Nagios       /usr/share/check_mk/pnp-rraconf         
 compile livestatus module       yes                                     
 check_mk's binary modules       /usr/lib/check_mk                       
 Unix socket for Livestatus      /var/log/nagios/rw/live                 
 Backends for other systems      /usr/share/check_mk/livestatus          
Proceed with installation (y/n)? y
(Compiling MK Livestatus.......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................)
Installation completed successfully.
Please restart Nagios and Apache in order to update/active check_mk's web pages.
You can access the new Multisite GUI at http://localhost/check_mkcheck_mk/

On va installer le package agent :

Command dpkg
dpkg -i check-mk-agent_1.1.12p7-2_all.deb

Nous allons créer le dossier du socket et lui attribuer les droits :

mkdir -p /var/lib/nagios3/rw/
touch /var/lib/nagios3/rw/live
chown -Rf nagios. /var/lib/nagios3

3.2 Xinetd

Configurez xinetd :

Configuration File /etc/xinetd.d/livestatus
service livestatus
    type = UNLISTED
    port = 6557
    socket_type = stream
    protocol = tcp
    wait = no
    cps = 100 3
    instances = 500
    per_source = 250
    flags = NODELAY
    user = nagios
    server = /usr/bin/unixcat
    server_args = /var/lib/nagios3/rw/live
    only_from = # modify this to only allow specific hosts to connect, currenly localhost only
    disable = no

Et redémarrez :

/etc/init.d/xinetd restart

3.3 Apache

Nous allons pour commencer créer un fichier htpasswd qui contiendra le user authoriser à se connecter. Libre à vous de le faire se connecter sur un LDAP ou autre plus tard :

Command htpasswd
> htpasswd -c /etc/nagios/htpasswd.users nagiosadmin
New password: 
Re-type new password: 
Adding password for user nagiosadmin

Nous allons donner des droits supplémentaires à Apache pour la partie interface graphique, afin qu'il puisse l'afficher :

usermod -G nagios -a www-data
mkdir /var/lib/check_mk/web/nagiosadmin
chown nagios:www-data /var/lib/check_mk/web/
chmod ug+rwx /var/lib/check_mk/web/

Redémarrez Apache si besoin car vous avez peut être des nouveaux modules (comme mod_python) qui viennent juste d'être installé.

3.4 Nagios

Vérifiez que vos lignes de configuration de Nagios ressemble à ceci (normalement ces lignes ont été ajoutées automatiquement à la fin de votre fichier de configuration) :

Configuration File /etc/nagios3/nagios.cfg
# Load Livestatus Module
broker_module=/usr/lib/check_mk/livestatus.o /var/lib/nagios3/rw/live[...]

Vérifiez néanmoins que la fin de la ligne correspond bien car dans le setup, nous n'avons pas spécifier celui ci.

Et pour finir redémarrez Nagios. Dans vos logs (syslog), vous devriez voir ceci :

Configuration File /var/log/syslog
Apr  4 11:28:36 nagios nagios3: Nagios 3.2.1 starting... (PID=17414)
Apr  4 11:28:36 nagios nagios3: Local time is mer. avril 04 11:28:36 CEST 2012 
Apr  4 11:28:36 nagios nagios3: LOG VERSION: 2.0
Apr  4 11:28:36 nagios nagios3: livestatus: Livestatus 1.1.12p7 by Mathias Kettner. Socket: '/var/log/nagios/rw/live'
Apr  4 11:28:36 nagios nagios3: livestatus: Please visit us at
Apr  4 11:28:36 nagios nagios3: livestatus: Hint: please try out OMD - the Open Monitoring Distribution
Apr  4 11:28:36 nagios nagios3: livestatus: Please visit OMD at
Apr  4 11:28:36 nagios nagios3: livestatus: Finished initialization. Further log messages go to /var/log/nagios3/livestatus.log
Apr  4 11:28:36 nagios nagios3: Event broker module '/usr/lib/check_mk/livestatus.o' initialized successfully.

4 Utilisation

Pour l'utiliser c'est très simple, voici quelques exemples pour récupérer des infos :

Command echo
echo 'GET services' | unixcat /var/lib/nagios3/rw/live
echo 'GET hosts' | unixcat /var/lib/nagios3/rw/live

Pour plus d'informations :

Et vous pouvez utilisez l'interface web ici : http://nagios/check_mkcheck_mk

5 Ressources