English English

Icinga2 - Publier votre notification Icinga2 sur Twitter

Vous pouvez également tweeter votre notification Icinga2 sur votre compte Twitter. Cette méthode de notification peut s'exécuter en plus de vos méthodes de notification existantes telles que l'e-mail, etc.

Vous devez créer un compte Twitter si vous n'en avez pas. Vous pouvez utiliser votre compte Twitter normal et vous n'avez pas besoin d'un compte développeur ou d'un compte spécial.

Exigences

Ubuntu est utilisé comme système d'exploitation dans ce tutoriel. Vous devez avoir Icinga2 installé et configuré. Ce tutoriel traite uniquement de l'installation et de la configuration d'un Icinga2 pour qu'il envoie ses notifications également par tweets sur Twitter.

Installer et configurer Twidge

Ce programme est disponible sur le répertoire officiel d'Ubuntu et peut être installé via le gestionnaire de paquets "apt".

apt-get install twidge


Maintenant, vous devez exécuter l'installation. Ceci se fait avec cette commande.

twidge setup

Suivez les instructions de ce programme. Ensuite, vous devez vous connecter à votre compte Twitter que vous voulez utiliser et ouvrir l'URL qui est affiché dans ce programme . Vous devez autoriser l'accès à votre compte Twitter, c'est pourquoi vous avez besoin de ce processus d'autorisation.

Maintenant vous devez copier le fichier de configuration de ce programme "twidge" dans votre dossier icinga2.

sudo cp ~/.twidgerc /etc/icinga2/twidgerc

Vous pouvez supprimer le fichier de configuration original "~/.twidgerc", si vous n'en avez plus besoin.
Mais le fichier de configuration /etc/icinga2/twidgerc (qui est utilisé ici - vous pouvez aussi changer un autre chemin) sera utilisé par "twidgerc" pour créer des tweets depuis votre notification Icinga2.


Créer des scripts de notification pour Icinga2

Passez ensuite dans le répertoire scripts de votre dossier Icinga2 et créez les scripts de notification pour la notification de l'hôte et du service. Vous devez vous rappeler que vous devez garder votre message dans la commande "echo" court, car vous avez une limite de 140 caractères sur vos tweets.

Créer un script shell de notification de l'host

vim /etc/icinga2/scripts/twitter-host-notification.sh
#!/bin/sh
/bin/echo "#$NOTIFICATIONTYPE - SERVER #$HOSTALIAS is $HOSTSTATE." | twidge -c /etc/icinga2/twidgerc update


Créer un script shell de notification de service

vim /etc/icinga2/scripts/twitter-service-notification.sh
#!/bin/sh
/bin/echo "#$NOTIFICATIONTYPE - SERVICE $SERVICEDISPLAYNAME on Server $HOSTALIAS is $SERVICESTATE." | twidge -c /etc/icinga2/twidgerc update


Maintenant, les scripts du shell de notification créés doivent obtenir les permissions correctes pour le fichier.

chmod +x /etc/icinga2/scripts/twitter-service-notification.sh
chmod +x /etc/icinga2/scripts/twitter-host-notification.sh


Configurer les notifications sur Icinga2

Dans ce tutoriel, nous allons utiliser le compte administrateur "icingaadmin" comme exemple.

1. Ajoutez une NotificationCommand pour la notification de l'hôte et du service.

vim /etc/icinga2/conf.d/commands.conf
object NotificationCommand "twitter-host-notification" {
  import "plugin-notification-command"

  command = [ SysconfDir + "/icinga2/scripts/twitter-host-notification.sh" ]

  env = {
    NOTIFICATIONTYPE = "$notification.type$"
    HOSTNAME = "$host.name$"
    HOSTALIAS = "$host.display_name$"
    HOSTADDRESS = "$address$"
    HOSTSTATE = "$host.state$"
    LONGDATETIME = "$icinga.long_date_time$"
    HOSTOUTPUT = "$host.output$"
    NOTIFICATIONAUTHORNAME = "$notification.author$"
    NOTIFICATIONCOMMENT = "$notification.comment$"
    HOSTDISPLAYNAME = "$host.display_name$"
    }
}

object NotificationCommand "twitter-service-notification" {
  import "plugin-notification-command"

  command = [ SysconfDir + "/icinga2/scripts/twitter-service-notification.sh" ]

  env = {
    NOTIFICATIONTYPE = "$notification.type$"
    SERVICEDESC = "$service.name$"
    HOSTNAME = "$host.name$"
    HOSTALIAS = "$host.display_name$"
    HOSTADDRESS = "$address$"
    SERVICESTATE = "$service.state$"
    LONGDATETIME = "$icinga.long_date_time$"
    SERVICEOUTPUT = "$service.output$"
    NOTIFICATIONAUTHORNAME = "$notification.author$"
    NOTIFICATIONCOMMENT = "$notification.comment$"
    HOSTDISPLAYNAME = "$host.display_name$"
    SERVICEDISPLAYNAME = "$service.display_name$"
  }
}


2. Ouvrez le fichier /etc/icinga2/conf.d/templates.conf
Dans ce fichier se trouvent les modèles de vos hôtes et services qui devraient ressembler à ceci :

template Host "generic-host" {

[...]

}


Ajoutez cette variable à tous les modèles ("Host", "Service") que vous utilisez :

vars.notification["twitter"] = {
    users = [ "icingaadmin" ]
}

Vous devez également ajouter les modèles pour les avis dans ce même fichier.
Qui ressemble à ceci :

template Notification "twitter-host-notification" {
  command = "twitter-host-notification"

  states = [ Up, Down ]
  types = [ Problem, Acknowledgement, Recovery, Custom ]
vars.notification_interval = 0

  period = "24x7"
}

/**
 * Provides default settings for service notifications.
 * By convention all service notifications should import
 * this template.
 */
template Notification "twitter-service-notification" {
  command = "twitter-service-notification"
  vars.notification_interval = 0

  states = [ OK, Warning, Critical, Unknown ]
  types = [ Problem, Acknowledgement, Recovery, Custom ]

  period = "24x7"
}

Vous devez maintenant ajouter la notification à vos services et hôtes. Vous pouvez le faire facilement avec la commande "appliquer Notification".

3. Ajoutez ceci au fichier /etc/icinga2/conf.d/notifications.conf

apply Notification "twitter-icingaadmin" to Host {
  import "mail-host-notification"
  command = "twitter-host-notification"

  users = [ "icingaadmin" ]
  interval = 0 //disable re-notification

  assign where host.vars.notification.twitter

}

apply Notification "twitter-icingaadmin" to Service {
  import "mail-service-notification"
  command = "twitter-service-notification"
  interval = 0 //disable re-notification

  users = [ "icingaadmin" ]

  assign where host.vars.notification.twitter

}


4. Et enfin, le fichier de configuration du programme "twidgerc" doit avoir les bonnes permissions.

chmod 644 /etc/icinga2/twidgerc
chown nagios:nagios /etc/icinga2/twidgerc


Redémarrez maintenant Icinga2 et vous avez terminé.

Vous pouvez aussi personnaliser par exemple les scripts créés dans ce tutoriel dans le dossier "/etc/icinga2/scripts/" pour exécuter différentes commandes en fonction de l'état du service d'un service. L'état d'un service peut être vérifié par la variable "$SERVICESTATE".

Voici un exemple sur la façon de configurer les notifications Icinga2 pour Twitter.

 

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.

Ok