Giter Club home page Giter Club logo

hipsaint's Introduction

HipSaint

Push your nagios notifications to HipChat using a simple command line tool.

https://travis-ci.org/hannseman/hipsaint.png?branch=master

Implements HipChat message API.

Inspired by https://gist.github.com/2418848.

Install

Through pip:

pip install hipsaint

Or clone and simply run:

python setup.py install

Usage in Nagios

Assuming you use Nagios 3 add the following sections to commands.cfg with <TOKEN> and <ROOM_ID> specified and macros delimited by |:

define command {
    command_name    notify-host-by-hipchat
    command_line    hipsaint -V 2 --token=<TOKEN> --room=<ROOM_ID> --type=host --inputs="$HOSTNAME$|$LONGDATETIME$|$NOTIFICATIONTYPE$|$HOSTADDRESS$|$HOSTSTATE$|$HOSTOUTPUT$" -n
}
define command {
    command_name    notify-service-by-hipchat
    command_line    hipsaint -V 2 --token=<TOKEN> --room=<ROOM_ID> --type=service --inputs="$SERVICEDESC$|$HOSTALIAS$|$LONGDATETIME$|$NOTIFICATIONTYPE$|$HOSTADDRESS$|$SERVICESTATE$|$SERVICEOUTPUT$" -n
}

To send less verbose messages to hipchat set the --type flag to either short-host or short-service.

Additional commands is available through:

hipsaint --help

Edit the Nagios contacts.cfg file by adding or editing an existing user and adding the notification commands created above:

define contact {
        ....
        .....
        service_notification_commands   notify-service-by-hipchat
        host_notification_commands      notify-host-by-hipchat
        email   /dev/null
}

Usage in Icinga 2

To use Hipsaint in Icinga 2, you can create an additional config like this :

Create two scripts, one for hosts, one for services :

Don't forget to fill <TOKEN> and <ROOM_ID>.

Hosts : /etc/icinga2/scripts/hipchat-host-notification.sh

   #!/bin/bash


hipsaint -V 2 --token=<TOKEN> --room=<ROOM_ID> --type=host --inputs="$HOSTNAME|$LONGDATETIME|$NOTIFICATIONTYPE|$HOSTADDRESS|$HOSTSTATE|$HOSTOUTPUT|$NOTIFICATIONAUTHOR|$NOTIFICATIONCOMMENT" -n

Services : /etc/icinga2/scripts/hipchat-service-notification.sh

   #!/bin/bash

hipsaint -V 2 --token=<TOKEN> --room=<ROOM_ID> --type=service --inputs="$SERVICEDESC|$HOSTALIAS|$LONGDATETIME|$NOTIFICATIONTYPE|$HOSTADDRESS|$SERVICESTATE|$SERVICEOUTPUT|$NOTIFICATIONAUTHOR|$NOTIFICATIONCOMMENT" -n

Then you need to tell Icinga to use those scripts :

Create a file called hipsaint.conf in your conf.d directory

/**
 * Hipchat/Hipsaint script for Icinga2
 *
 * Only applied if host/service objects have
 * the custom attribute `sla` set to `24x7`.
 */

object NotificationCommand "notify-host-by-hipchat" {
  import "plugin-notification-command"

  command = [ "/etc/icinga2/scripts/hipchat-host-notification.sh" ]

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

object NotificationCommand "notify-service-by-hipchat" {
  import "plugin-notification-command"

  command = [ "/etc/icinga2/scripts/hipchat-service-notification.sh" ]

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

apply Notification "hipchat-icingaadmin" to Host {
  command = "notify-host-by-hipchat"

  user_groups = [ "icingaadmins" ]

  assign where host.vars.sla == "24x7"
}

apply Notification "hipchat-icingaadmin" to Service {
  command = "notify-service-by-hipchat"

  user_groups = [ "icingaadmins" ]

  assign where service.vars.sla == "24x7"
}

You want to customize this to your groups and users.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.