Giter VIP home page Giter VIP 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 --user=Icinga --token=<TOKEN> --room=<ROOM_ID> --type=host --inputs="$HOSTNAME|$LONGDATETIME|$NOTIFICATIONTYPE|$HOSTADDRESS|$HOSTSTATE|$HOSTOUTPUT" -n

or

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

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

   #!/bin/bash

   hipsaint --user=Icinga --token=<TOKEN> --room=<ROOM_ID> --type=service --inputs="$SERVICEDESC|$HOSTALIAS|$LONGDATETIME|$NOTIFICATIONTYPE|$HOSTADDRESS|$SERVICESTATE|$SERVICEOUTPUT" -n

or
    hipsaint -V 2 --token=<TOKEN> --room=<ROOM_ID> --type=service --inputs="$SERVICEDESC|$HOSTALIAS|$LONGDATETIME|$NOTIFICATIONTYPE|$HOSTADDRESS|$SERVICESTATE|$SERVICEOUTPUT" -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$"
  }
}

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

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.

hipsaint's People

Contributors

adam-nowotny avatar akun avatar hannseman avatar joar avatar jwojcik avatar loganbest avatar mtn-rowinandruscavage avatar rtkjbillo avatar thomaschristory avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hipsaint's Issues

401/403 unauthorized but pipeline test but hipchatsend works

Printed args to stdout for review

hipsaint --user Operations --token SOME_ORKEN --room 'Operations' --type host --inputs "$HOSTNAME|$LONGDATETIME|$NOTIFICATIONTYPE|$HOSTADDRESS|$HOSTSTATE|$HOSTOUTPUT" -n
{'inputs': 'host.domain.com|||||', 'api_host': 'api.hipchat.com', 'msg_type': 'host', 'msg_format': 'html', 'token': 'SOME_TOKEN', 'room_id': 'Operations', 'notify': True, 'proxy': '', 'api_version': '1', 'user': 'Operations'}
[]
Traceback (most recent call last):
  File "/home/icinga/.local/share/virtualenvs/hipsaint-K_QnKhoc/bin/hipsaint", line 11, in <module>
    sys.exit(main())
  File "/home/icinga/.local/share/virtualenvs/hipsaint-K_QnKhoc/lib/python2.7/site-packages/hipsaint/bin/commands.py", line 80, in main
    msg.deliver_payload()
  File "/home/icinga/.local/share/virtualenvs/hipsaint-K_QnKhoc/lib/python2.7/site-packages/hipsaint/messages.py", line 73, in deliver_payload_v1
    raw_response = urlopen(self.urlv1, message_params)
  File "/usr/lib64/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib64/python2.7/urllib2.py", line 437, in open
    response = meth(req, response)
  File "/usr/lib64/python2.7/urllib2.py", line 550, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib64/python2.7/urllib2.py", line 475, in error
    return self._call_chain(*args)
  File "/usr/lib64/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "/usr/lib64/python2.7/urllib2.py", line 558, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 401: Unauthorized

duplicate notifications

Every notification generated by my icinga2 setup is generating duplicate messages in hipchat. Have you seen this before?
screenshot 2015-09-25 09 48 06
Let me know what would be useful in debugging this isseue.

Also, thank you so much for putting this project out there, it's a very convenient thing to have =)

bug hipsaint/messages.py -

I have noticed that their is bug on messages.py/Line 40:
self.urlv2 = 'https://{0}/v2/room/{1}/notification'.format(self.host, self.room_id)
This should be:
self.urlv2 = 'https://{0}/v2/room/{1}/message'.format(self.host, self.room_id)
So you have to change "notification" by "message" for the message to pass via hipchat API V2.

notification not triggered

no notification triggered hence I added the -n & tried --notify
my command is
hipsaint -V 2 -t ************* -r *** -i "$SERVICEDESC$|$HOSTALIAS$|$LONGDATETIME$|$NOTIFICATIONTYPE$|$HOSTADDRESS$|$SERVICESTATE$|$SERVICEOUTPUT$" -T service -n

The message arrives with no notification!
Ubuntu16.04 & Python 2.7.12

Medium template truncating important alert info

Running into where an alert is loosing important data in the notification. The notification is only showing the first line of data:

The alert in Nagios Core is reading
Status Information: Critical Cert "Cert_01.crt" will expire in 0 days
Critical Cert "Cert_02.crt" will expire in 0 days

Notification is only coming through only showing that Cert_01.crt and trying to use "$LONGSERVICEOUTPUT$" isn't showing the the verbose data.

getting hostname not hostalias

I am adjusting the service template to output nagios link to host detail and put this in hipchat. I have tried adjusting it and can only get host alias out of the alert. How can I get the hostname?

Any help would be appreciated.

Thanks!!

No JSON object could be decoded

I try to test it from cmd, but then i run command with my token, room id, host - it return error: "ValueError: No JSON object could be decoded"

Need more than 1 value to unpack

I'm getting an error message trying to use this:

root@icinga-master:/usr/local/etc/icinga2/conf.d # hipsaint --user=Icinga --token=THETOKEN --room=THEROOM --type=service --inputs="Hello World" -n
Traceback (most recent call last):
File "/usr/local/bin/hipsaint", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python2.7/site-packages/hipsaint/bin/commands.py", line 78, in main
msg.deliver_payload()
File "/usr/local/lib/python2.7/site-packages/hipsaint/messages.py", line 58, in deliver_payload_v1
message_body = self.render_message()
File "/usr/local/lib/python2.7/site-packages/hipsaint/messages.py", line 146, in render_message
template_context = self.get_service_context()
File "/usr/local/lib/python2.7/site-packages/hipsaint/messages.py", line 126, in get_service_context
servicedesc, hostalias, timestamp, ntype, hostaddress, state, serviceoutput = self.inputs_list
  ValueError: need more than 1 value to unpack

no /usr/bin/hipsaint on install

wondering if either install methods are supposed to add the command to /usr/bin/ for the latest release.

I do see that a previous version has it installed fine on another machine.

support v2

Hi,

Could you Please clarify ,

Shall i use this procedure for hipchat API-2 [beta] . if it supports, Please share the details what we have to do / follow.

possible "option" to use full hostname ??

Hi all,

  1. Thanks for the plugin .. Very much appreciated ..

  2. would it be possible to define some "option" that would allow you to send to hipchat the full hostname vs the abbreviated one ?? for example, in the messages.py on line 90 there is this code:

nagios_host = socket.gethostname().split('.')[0]

we have multiple nagios servers and we follow a naming convention like:

admin.ae1b.mydomain.net
admin.ae1a.mydomain.net

the message in hipchat is displayed as:

"Fri Aug 22 13:57:43 EDT 2014 - Status Page on XYZ (nagios@admin)"
...

It would be nice to know the full hostname so we know exactly which nagios server is sending us this alert .. Does that make any sense ??

Thanks again for the great plugin !!
Greg

alert description

Hi,

i have integrated with nagios and it started to send a alert to hipchat. Thanks for that .

But

  1. i like to re-define the format of alert msg. it need to have all details.
  2. the Alert not sending the problem [service failure] details it only sending the alert with hostname on which the problem occurred.
    i configured the commands.cfg as per the steps what you have shared.
    Share your suggestions ..

Notifications not being sent from Icinga2

Hi,

I followed your instructions and created both scripts in /etc/icinga2/scripts and created hipsaint.conf in /etc/icigna2/conf.d but critical/warning notifications are still not being sent to hipchat:

I receive a notification when I execute hipchat-host-notification.sh manually, meaning the connection is established between icinga server and HipChat:

hipsaint.conf

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

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

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 host.vars.sla == "24x7"
}_

client:

object Host "bdb02.ppc1.mlt3.gamesys.local" {
check_command = "hostalive"
address = "10.201.32.130"
vars.client_endpoint = name
vars.os = "Red Hat 7.4"
vars.sla = "24x7"
vars.notification["mail"] = { groups = [ "icingaadmins" ] }
}

Any ideas please?

Thanks,
GNL

Remove dependencies

Today we depend on requests and jinja2. This is just bloated and could be done quite easily with urllib2 and string.Template or str.format(). requests and jinja2 are pretty fly though.

Add custom field

Hello, I love this plugin.
I have 2 questions:

  1. I have, for all my hosts, a host.vars.ref_email field and I would like to display it in the message. What is the best method

  2. This is an example of my message:

icinga2Bot·Nov-16 11:22 PM
2016-11-16 23:22:22 +0100 - icinga-master2.tp.xxx.it ([email protected])
Type: PROBLEM
Host: icinga-master2.tp.xxx.it (snoopy3x-VRR.tp.xxx.it)
State: 
Info:

Can I remove the user nagios@......

Thanks!
Riccardo

Python 2.4 support

[root@centreon hipsaint-master]# python setup.py install
Traceback (most recent call last):
File "setup.py", line 5, in ?
version = import('hipsaint').version
File "/root/hipsaint-master/hipsaint/init.py", line 16
parts = 2 if version[2] == 0 else 3
^
SyntaxError: invalid syntax

error if --inputs string contains pipes

EDIT: I am using the most recent version 0.6.0 of hipsaint

here's an example

--inputs="$SERVICEDESC|$HOSTALIAS|$LONGDATETIME|$NOTIFICATIONTYPE|$HOSTADDRESS|$SERVICESTATE|$SERVICEOUTPUT"

where
SERVICEDESC="Host | Section 1"

This causes the error:

Traceback (most recent call last):
File "/usr/local/bin/hipsaint", line 11, in
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/hipsaint/bin/commands.py", line 78, in main
msg.deliver_payload()
File "/usr/local/lib/python2.7/dist-packages/hipsaint/messages.py", line 58, in deliver_payload_v1
message_body = self.render_message()
File "/usr/local/lib/python2.7/dist-packages/hipsaint/messages.py", line 146, in render_message
template_context = self.get_service_context()
File "/usr/local/lib/python2.7/dist-packages/hipsaint/messages.py", line 126, in get_service_context
servicedesc, hostalias, timestamp, ntype, hostaddress, state, serviceoutput = self.inputs_list
ValueError: too many values to unpack

Putting extra quotes doesn't help:
--inputs="'$SERVICEDESC'|$HOSTALIAS|$LONGDATETIME|$NOTIFICATIONTYPE|$HOSTADDRESS|$SERVICESTATE|$SERVICEOUTPUT"

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.