Created
August 19, 2013 22:02
-
-
Save mikekunze/6274708 to your computer and use it in GitHub Desktop.
This is an example script that Nagios could use to send email notifications to contacts bound to alerts. See http://portalstack.blogspot.com/2012/07/sending-custom-nagios-notification.html for more information.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env coffee | |
# | |
# incoming argv is order sensitive | |
# | |
# [0] - coffee | |
# [1] - /opt/bin/notify-service.coffee | |
# [2] - hostname | |
# [3] - service | |
# [4] - IP address | |
# [5] - notification type [ PROBLEM, RECOVERY, OK ] | |
# [6] - status [ OK, WARNING, CRITICAL ] | |
# [7] - long date time | |
# [8] - service output | |
require 'coffee-script' | |
nodemailer = require 'nodemailer' | |
jade = require 'jade' | |
argvObject = | |
hostname: process.argv[2] | |
service: process.argv[3] | |
ip: process.argv[4] | |
notify_type: process.argv[5] | |
status: process.argv[6] | |
date: process.argv[7] | |
output: process.argv[8] | |
smtpTransport = nodemailer.createTransport "SMTP" | |
text = "Nagios requires your attention.\n | |
\n | |
Hostname:\t\t" + argvObject.hostname + "\n | |
service:\t\t" + argvObject.service + "\n | |
ip:\t\t" + argvObject.ip + "\n | |
notify:\t\t" + argvObject.notify_type + "\n | |
status:\t\t" + argvObject.status + "\n | |
date:\t\t" + argvObject.date + "\n | |
output:\t\t" + argvObject.output + "\n | |
" | |
jade.renderFile '/opt/bin/jade/nagiosAlert.jade', argvObject, (err, html)-> | |
if err | |
console.log err | |
mailOptions = | |
from: "Nagios <[email protected]>" | |
to: "[email protected]" | |
subject: argvObject.hostname + "'s " + argvObject.service + | |
" IS " + argvObject.status | |
text: text | |
html: html | |
smtpTransport.sendMail mailOptions, (err, res) -> | |
if err | |
console.log err | |
process.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment