Installation et configuration de Icinga2 et Icinga2web

Le monitoring d’une infrastructure

La place de la surveillance dans une infrastructure est indispensable notamment avec la multiplications des serveurs, de ses services ainsi que des éléments actifs sur le réseau.

Les solutions libres pour le monitoring sont nombreuses, il y a quelques années le plus utilisé était Nagios. Il a inspiré de nombreux projets (fork de Nagios) par exemple la version 1 de Icinga été un fork dû au mécontentement des utilisateurs.

Avec le temps Icinga2 est devenu un projet unique et indépendant, c’est celui ci que je souhaite vous faire découvrir.

Icinga2

Lancé en 2014, la version a été ré-écrite, elle n’est plus un fork de Nagios mais est totalement indépendante. Elle permet encore d’implémenter des plugins Nagios et possède une interface web des plus moderne nommée Icinga2web :

Dans cet article, nous découvrirons comment installer Icinga2 et Icinga2web, puis nous allons surveiller un serveur Debian, un serveur Windows 2012 r2 et utiliseront le protocole SNMP sur un routeur VyOS.

Installation : Icinga2 et Icinga2web

Le processus d’installation est simple, elle est expliquée sur la documentation officielle ou sur Github.
Dans notre cas l’installation se déroule sous Debian 8 en version x64.

Icinga2

  1. Ajoutons les dépôt Icinga2 et la clé :
    echo 'deb http://packages.icinga.org/debian icinga-jessie main' >>/etc/apt/sources.list
    echo 'deb-src http://packages.icinga.org/debian icinga-jessie main' >>/etc/apt/sources.list
    wget -O - http://packages.icinga.com/icinga.key | apt-key add -
  2. Une mise à jour des dépôts est nécessaire :
     apt-get update 
  3. Nous installons le paquet Icinga2
    apt-get install icinga2
  4. L’installation de la base de donnée MySQL :
    apt-get install mysql-server mysql-client
  5. L’installation de paquet : N’oublions pas, durant l’installation d’activer les fonctionnalités « oui »
    apt-get install icinga2-ido-mysql
  6. Une fois terminé, le fichier de configuration est présent dans :
    /etc/icinga2/features-available/ido-mysql.conf
  7. Lançons le service Icinga2
    service icinga2 start
  8. Puis activons la fonction ido-mysql dans Icinga2
    icinga2 feature enable ido-mysql command

Icinga2web

  1. L’installation du serveur web Apache2 :
    apt-get install apache2
  2. L’installation de dépendance de PHP5  :
    apt-get install php5-intl php5-imagick
  3. Changeons l’heure de la zone dans Apache dans le fichier suivant :

    nano /etc/php5/apache2/php.ini
    date.timezone = europe/paris
  4. Redémarrons le service web :

    /etc/init.d/apache2 restart
  5. Puis installons le paquet Icinga2web :
    apt-get install icingaweb2
  6. Avant de procéder à la configuration, nous générons un token :
    icingacli setup token create

Configuration : Icinga2web et Icinga2

Désormais nous sommes prêts à nous rendre sur l’interface Icinga2web via https://127.0.0.1/icingaweb2/setup

Utilisons le token généré précédemment :

La mode de sélection de certains modules :

Le récapitulatif des conditions requises :

Le type d’authentification en base de données :

La connexion à la database avec les identifiants du mysql :

Le choix d’un nom aux paramètres de connexion :

Le choix d’un nom aux paramètres de connexion : 

Création du compte administrateur :

La configuration de l’application (par défaut) :

Le résumé de la configuration :

A partir de maintenant nous allons configurer le module Monitoring Backend :

La dernière étape consiste simplement à restituer la configuration de fichiers :
/etc/icinga2/features-available/ido-mysql.conf

Terminons l’installation d’Icinga2web

La première connexion à l’interface web ressemble au résultat suivant :

Nous avons terminé les étapes nécessaires à l’implantation d’Icinga2web.

Le serveur maître est actuellement surveillé avec des vérifications par défaut.
Nous avons un port SSH qui écoute sur un port différent, actuellement défaut, voici comme le modifier :

/etc/icinga2/conf.d/hosts.conf

Rajoutons la variable suivante :

vars.ssh_port = 2222

La configuration du serveur maître

Pour que le serveur soit capable de surveiller des hôtes, utilisons la commande suivante :

icinga2 node wizard

Afin que notre serveur soit le maître, nous allons suivre la instructions suivante :

Please specify if this is a satellite setup ('n' installs a master setup) [Y/n]: n

Please specifiy the common name (CN) [watchyou]:

Checking for existing certificates for common name 'watchyou'...
Certificates not yet generated. Running 'api setup' now.
information/cli: Generating new CA.
information/base: Writing private key to '/var/lib/icinga2/ca/ca.key'.
information/base: Writing X509 certificate to '/var/lib/icinga2/ca/ca.crt'.
information/cli: Generating new CSR in '/etc/icinga2/pki/watchyou.csr'.
information/base: Writing private key to '/etc/icinga2/pki/watchyou.key'.
information/base: Writing certificate signing request to '/etc/icinga2/pki/watchyou.csr'.
information/cli: Signing CSR with CA and writing certificate to '/etc/icinga2/pki/watchyou.crt'.
information/pki: Writing certificate to file '/etc/icinga2/pki/watchyou.crt'.
information/cli: Copying CA certificate to '/etc/icinga2/pki/ca.crt'.
Generating master configuration for Icinga 2.
information/cli: Adding new ApiUser 'root' in '/etc/icinga2/conf.d/api-users.conf'.
information/cli: Enabling the 'api' feature.
Enabling feature api. Make sure to restart Icinga 2 for these changes to take effect.
information/cli: Dumping config items to file '/etc/icinga2/zones.conf'.
information/cli: Created backup file '/etc/icinga2/zones.conf.orig'.
Please specify the API bind host/port (optional):
Bind Host []:
Bind Port []:
information/cli: Created backup file '/etc/icinga2/features-available/api.conf.orig'.
information/cli: Updating constants.conf.
information/cli: Created backup file '/etc/icinga2/constants.conf.orig'.
information/cli: Updating constants file '/etc/icinga2/constants.conf'.
information/cli: Updating constants file '/etc/icinga2/constants.conf'.
information/cli: Updating constants file '/etc/icinga2/constants.conf'.
Done.

Now restart your Icinga 2 daemon to finish the installation!

Nous redémarrons Icinga2 :

/etc/init.d/icinga2 restart

L’ajout d’un serveur Linux

Nous allons devoir télécharger le paquet Icinga2 sur le serveur Linux que nous souhaitons monitorer.
Puis, la commande est identique que sur le serveur maître :

icinga2 node wizard

Sur un serveur que l’on souhaite monitorer, la configuration est différente :

Please specify if this is a satellite setup ('n' installs a master setup) [Y/n]: Y
Please specifiy the common name (CN) [owncloud.kassianoff.ovh]: owncloud
Master Common Name (CN from your master setup): icinga
Do you want to establish a connection to the master from this node? [Y/n]: Y
Master endpoint host (Your master's IP address or FQDN): 192.168.0.3
Master endpoint port [5665]:
Add more master endpoints? [y/N]: N
Please specify the master connection for CSR auto-signing (defaults to master endpoint host):
Host [192.168.0.3]:
Port [5665]: 
information/base: Writing private key to '/etc/icinga2/pki/owncloud.key'.
information/base: Writing X509 certificate to '/etc/icinga2/pki/owncloud.crt'.
information/cli: Fetching public certificate from master (192.168.0.3, 5665):
Certificate information:

Subject:     CN = icinga
Issuer:      CN = Icinga CA
Valid From:  Sep 29 18:50:46 2016 GMT
Valid Until: Sep 26 18:50:46 2031 GMT
Fingerprint: D0 6B 09 7D CB 53 3D FE A7 70 35 1A 88 77 8E 8C 60 6A A5 F5

Is this information correct? [y/N]: y

Please specify the request ticket generated on your Icinga 2 master. 
(Hint: # icinga2 pki ticket --cn 'owncloud'): bfde48f974c9aac682dc19f80d47a0083be254e0information/cli: 
Requesting certificate with ticket 'bfde48f974c9aac682dc19f80d47a0083be254e0'.
information/cli: Created backup file '/etc/icinga2/pki/owncloud.crt.orig'.
information/cli: Writing signed certificate to file '/etc/icinga2/pki/owncloud.crt'.
information/cli: Writing CA certificate to file '/etc/icinga2/pki/ca.crt'.
Please specify the API bind host/port (optional):
Bind Host []:
Bind Port []:
Accept config from master? [y/N]: y
Accept commands from master? [y/N]: y

Durant la procédure il est demandé de ce connecter sur le serveur maître et d’exécuter la commande :

icinga2 pki ticket --cn 'owncloud'
bfde48f974c9aac682dc19f80d47a0083be254e0
La commande vous génère un token qui identifie la machine de façon unique.

Mise à jour de la configuration du server maître

Désormais, rendons-nous sur le serveur maître car il est nécessaire de faire une mise à jour de la configuration :

icinga2 node update-config

A ce moment précis Owncloud est présent mais il faut redémarrer Icinga2 :

/etc/init.d/icinga2 restart
Le résultat devrait apparaître dans l’interface Icinga2web.

L’ajout d’un serveur Windows

La procédure d’installation d’Icinga2 est graphique, rendons-nous sur le dépot de téléchargement  : http://packages.icinga.org/windows/ puis executons le fichier : icinga2-snapshot-x86_64.msi et l’installation icinga2setup wizard comme ceci :

Une fois l’installation terminée il faut relancer le service Icinga2 sous Windows :

net stop icinga2
net start icinga2

Là encore, une mise à jour du node sur le serveur maître est nécessaire :

information/cli: Updating node configuration for
Node 'windows2k12' (last seen: Sat Nov 26 17:47:34 2016)
    * Host 'windows2k12'
        * Service 'disk'
        * Service 'disk C:'
        * Service 'icinga'
        * Service 'load'
        * Service 'ping4'
        * Service 'ping6'
        * Service 'procs'
        * Service 'swap'
        * Service 'users'
information/cli: Adding host 'windows2k12' to the repository.
information/cli: Dumping changelog items to file '/var/lib/icinga2/repository/changes/1480182452.069441-Host-74c8bf8d716b8a06cb3574f1459547b5c16188ab48020bcb3fcc32e0d2b916e6.change'
information/cli: Dumping changelog items to file '/var/lib/icinga2/repository/changes/1480182452.072007-Service-1044dec7206e8d7c9fbb4ae8f766668406d2567fc7fc1a160a9d4700fcf8f8e9.change'
information/cli: Dumping changelog items to file '/var/lib/icinga2/repository/changes/1480182452.073057-Service-11cbac783763adafaf46fb769e695a9ac22afccfc9493ac485c2386252c636d1.change'
information/cli: Dumping changelog items to file '/var/lib/icinga2/repository/changes/1480182452.074116-Service-2eb9c534258d20f7c437141670d7c09d7afbab65b2ac9cd2034be27b122cbb41.change'
information/cli: Dumping changelog items to file '/var/lib/icinga2/repository/changes/1480182452.075129-Service-0cf67fc72b3c86c7a454f6d86b43ed245a8e491d0e5288d4da8c7ff43a7bcdb0.change'
information/cli: Dumping changelog items to file '/var/lib/icinga2/repository/changes/1480182452.076148-Service-571605952ba28ee6740b5a9b50f1e76393f1e4cdaf3115438bcdeddf8e473065.change'
information/cli: Dumping changelog items to file '/var/lib/icinga2/repository/changes/1480182452.077172-Service-d7535967c0481dbeb28afe542a40e2f0687f4fc5b5fc5abafacbd4c24ff0d9cf.change'
information/cli: Dumping changelog items to file '/var/lib/icinga2/repository/changes/1480182452.078285-Service-277d2f898036fa83a8f790fd6680e3c89e2cceaa4921a17b6ccb6c8f464ebb97.change'
information/cli: Dumping changelog items to file '/var/lib/icinga2/repository/changes/1480182452.079331-Service-da47c2f450a4f9d538d86d600d55149afd39d6672fdd1f30c68ad5be21cadad8.change'
information/cli: Dumping changelog items to file '/var/lib/icinga2/repository/changes/1480182452.080394-Service-7dfb4cf67742cb0660305e56ef816c53fcec892cae7f6ee39b75f34e659d672c.change'
information/cli: Adding endpoint 'windows2k12' to the repository.
information/cli: Dumping changelog items to file '/var/lib/icinga2/repository/changes/1480182452.081559-Endpoint-74c8bf8d716b8a06cb3574f1459547b5c16188ab48020bcb3fcc32e0d2b916e6.change'
information/cli: Adding zone 'windows2k12' to the repository.
information/cli: Dumping changelog items to file '/var/lib/icinga2/repository/changes/1480182452.084995-Zone-74c8bf8d716b8a06cb3574f1459547b5c16188ab48020bcb3fcc32e0d2b916e6.change'
information/cli: Committing node configuration.
Changes to be committed:

Adding host 'windows2k12'
    check_command = "cluster-zone"
    import = [ "satellite-host" ]
Adding service 'disk'
    check_command = "dummy"
    host_name = "windows2k12"
    import = [ "satellite-service" ]
    zone = "windows2k12"
Adding service 'disk C:'
    check_command = "dummy"
    host_name = "windows2k12"
    import = [ "satellite-service" ]
    zone = "windows2k12"
Adding service 'icinga'
    check_command = "dummy"
    host_name = "windows2k12"
    import = [ "satellite-service" ]
    zone = "windows2k12"
Adding service 'load'
    check_command = "dummy"
    host_name = "windows2k12"
    import = [ "satellite-service" ]
    zone = "windows2k12"
Adding service 'ping4'
    check_command = "dummy"
    host_name = "windows2k12"
    import = [ "satellite-service" ]
    zone = "windows2k12"
Adding service 'ping6'
    check_command = "dummy"
    host_name = "windows2k12"
    import = [ "satellite-service" ]
    zone = "windows2k12"
Adding service 'procs'
    check_command = "dummy"
    host_name = "windows2k12"
    import = [ "satellite-service" ]
    zone = "windows2k12"
Adding service 'swap'
    check_command = "dummy"
    host_name = "windows2k12"
    import = [ "satellite-service" ]
    zone = "windows2k12"
Adding service 'users'
    check_command = "dummy"
    host_name = "windows2k12"
    import = [ "satellite-service" ]
    zone = "windows2k12"
Adding endpoint 'windows2k12'
Adding zone 'windows2k12'
    endpoints = [ "windows2k12" ]
    parent = "watchyou"

information/cli: Writing config object 'windows2k12' to file '/etc/icinga2/repository.d/hosts/windows2k12.conf'
information/cli: Writing config object 'disk' to file '/etc/icinga2/repository.d/hosts/windows2k12/disk.conf'
information/cli: Writing config object 'disk C:' to file '/etc/icinga2/repository.d/hosts/windows2k12/disk C%3A.conf'
information/cli: Writing config object 'icinga' to file '/etc/icinga2/repository.d/hosts/windows2k12/icinga.conf'
information/cli: Writing config object 'load' to file '/etc/icinga2/repository.d/hosts/windows2k12/load.conf'
information/cli: Writing config object 'ping4' to file '/etc/icinga2/repository.d/hosts/windows2k12/ping4.conf'
information/cli: Writing config object 'ping6' to file '/etc/icinga2/repository.d/hosts/windows2k12/ping6.conf'
information/cli: Writing config object 'procs' to file '/etc/icinga2/repository.d/hosts/windows2k12/procs.conf'
information/cli: Writing config object 'swap' to file '/etc/icinga2/repository.d/hosts/windows2k12/swap.conf'
information/cli: Writing config object 'users' to file '/etc/icinga2/repository.d/hosts/windows2k12/users.conf'
information/cli: Writing config object 'windows2k12' to file '/etc/icinga2/repository.d/endpoints/windows2k12.conf'
information/cli: Writing config object 'windows2k12' to file '/etc/icinga2/repository.d/zones/windows2k12.conf'
Make sure to reload Icinga 2 for these changes to take effect.

Un redémarrage Icinga2 est aussi à réaliser sur le serveur maître :

/etc/init.d/icinga2 restart

Sur l’interface Icinga2web voici le résultat attendu :

L’ajout d’un hôte SNMP

Dans notre exemple nous ajouterons la surveillance via SNMP de VyOS.
L’instruction de commande permet l’ajout du SNMP public dans le réseau LAN vers une cible :

set service snmp listen-address 192.168.1.1
set service snmp listen-address 192.168.1.1 port 161
set service snmp target 192.168.1.2
set service snmp community public authorization rw
set service snmp description snmp-public
commit
save

Nous sommes désormais prêts à éditer la configuration du fichier :

nano /etc/icinga2/conf.d/hosts.conf

Nous ajoutons quelques vérifications comme par exemple le ping vers OVH ou encore les partitions :

object Host "vyos" {

 address             = "192.168.1.1"
 check_command       = "hostalive"
 vars.sla = "24x7"
 vars.fping_address = "91.121.161.184"
 vars.os = "Router-VyOS"
 vars.ssh_port = 14522
 vars.snmp_address   = "192.168.1.1"
 vars.snmp_community = "public"
 vars.snmp_v2        = "false"
 vars.snmp_v3        = "false"

vars.disks["disk /"] = {
    disk_partitions = "/",
  }

vars.disks["disk /boot"] = {
    disk_partitions = "/boot",
  }

vars.disks["disk"] = {
        vars.disk_wfree = "85%"
  }

}

La liste des vérifications à ajouter est disponible sur le lien suivant : la documentation.

Supprimer un hôte Icinga2

Supprimons l’entrée de l’hôte que nous souhaitons supprimer : (ex: windows2k12)

icinga2 node remove windows2k12

Puis, il nous exécutons la mise à jour du node :

icinga2 node update-config

A ce moment précis Windows n’est plus dans les nodes, nous redémarrons le service Icinga 2 :

/etc/init.d/icinga2 restart

Attention, il faut aussi faire la manipulation sur le client Windows, auquel cas au bout d’un certain temps il réapparaît.
Pour un hôte monitoré via l’agent, il faut reconfigurer l’hôte, et arréter le service Icinga2.
Concernant un hôte surveillé via SNMP par exemple, rendez-vous dans le fichier de configuration :

nano /etc/icinga2/conf.d/hosts.conf

Et supprimer les lignes de l’hôte précédemment insérées et relancer la mise à jour du node.

Ajouter des vérifications sur un hôte Icinga2

Nous avons trois hôtes qui communiquent de différentes façons avec notre solution icinga2 :

Il est désormais nécessaire de savoir manager nos vérifications afin d’en ajouter, d’en modifier ou d’en supprimer.
Les repertoires importants sont :

Les plugins Nagios dans icinga2 :

Malgré la nouveauté d’Icinga2, les plugins Nagios sont pleinement compatibles.
Pour utiliser des scripts de vérifications Nagios nous allons ajouter le paquet  : nagios-plugins :

apt-get install nagios-plugins

Il existe bon nombre de sondes de vérification à configurer avec Icinga2 que je n’exprime pas dans mon article.
Voici quelques adresses qui peuvent vous aider dans votre développement futur :
https://exchange.nagios.org/
https://exchange.icinga.com/
https://technet.microsoft.com/en-us/scriptcenter/bb410849.aspx

Bonne continuation avec Icinga2 qui est simplement un des meilleurs outils de monitoring gratuit.