English English

Icinga2 - Publica tu notificación de Icinga2 en Twitter

También puedes tuitear tu notificación de Icinga2 en tu cuenta de Twitter. Este método de notificación puede ejecutarse adicionalmente a sus métodos de notificación existentes, como el correo electrónico, etc.

Tienes que crear una cuenta de Twitter si no tienes una. Puedes usar tu cuenta normal de Twitter y no necesitas una cuenta de desarrollador ni ningún tipo especial de cuenta.

Requisitos

Ubuntu se utiliza como sistema operativo en este tutorial. Necesitas tener Icinga2 instalado y configurado. Este tutorial trata únicamente sobre cómo instalar y configurar un Icinga2 para que publique sus notificaciones también a través de tweets en Twitter.

Instalar y configurar Twidge

Este programa está disponible en el repositorio oficial de Ubuntu y se puede instalar a través del gestor de paquetes "apt".

apt-get install twidge


Ahora tiene que ejecutar la configuración. Esto se hace con este comando.

twidge setup

Siga las instrucciones de este programa. Luego tienes que iniciar sesión en la cuenta de Twitter que quieras usar y abrir la URL que se muestra en este programa. Tienes que autorizar el acceso a tu cuenta de twitter, por eso necesitas este proceso de autorización.

Ahora tiene que copiar el archivo de configuración de este programa "twidge" en su carpeta icinga2.

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

Puede borrar el archivo de configuración original "~/.twidgerc", si ya no lo necesita.
Pero el archivo de configuración /etc/icinga2/twidgerc (que se usa aquí - también puede cambiar otra ruta) será usado por "twidgerc" para crear tweets a partir de su notificación Icinga2.


Crear scripts de notificación para Icinga2

Luego cambie al directorio de scripts de su carpeta Icinga2 y cree los scripts de notificación para la notificación de host y servicio. Tienes que recordar que tienes que mantener tu mensaje en el comando "echo" corto, porque tienes un límite de caracteres de 140 caracteres en tus tweets.

Crear un script shell de notificación de host

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


Crear un script shell de aviso de servicio

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


Ahora los scripts shell de notificación creados tienen que obtener el permiso de archivo correcto.

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


Configurar notificaciones en Icinga2

Aquí en este tutorial usaremos la cuenta de administrador "icingaadmin" como ejemplo.

1. Agregue un comando de notificación tanto para el host como para el aviso de servicio.

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. Abra el archivo /etc/icinga2/conf.d/templates.conf
En este archivo se encuentran las plantillas de sus hosts y servicios que deberían tener un aspecto similar a este:

template Host "generic-host" {

[...]

}


Añada esta variable a todas las plantillas ("Host", "Service") que utilice:

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

Tiene que añadir también los modelos para las notificaciones en este mismo fichero.
Que se parece a esto:

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"
}

Ahora debe agregar la notificación a sus servicios y hosts. Puede hacerlo fácilmente con el comando "aplicar notificación".

3. Añade esto al fichero /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. Y finalmente, el archivo de configuración del programa "twidgerc" debe tener el permiso correcto.

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


Ahora reinicie Icinga2 y ya está.

También puede personalizar, por ejemplo, los scripts creados en este tutorial en la carpeta "/etc/icinga2/scripts/" para ejecutar diferentes comandos según el estado de servicio de un servicio. El estado de un servicio se puede comprobar mediante la variable "$SERVICESTATE".

Este fue un ejemplo de cómo configurar notificaciones de Icinga2 para Twitter.

 

Usamos cookies en nuestro sitio web. Algunas de ellas son esenciales para el funcionamiento del sitio, mientras que otras nos ayudan a mejorar el sitio web y también la experiencia del usuario (cookies de rastreo). Puedes decidir por ti mismo si quieres permitir el uso de las cookies. Ten en cuenta que si las rechazas, puede que no puedas usar todas las funcionalidades del sitio web.