Created
July 14, 2012 16:02
-
-
Save mikekunze/3111907 to your computer and use it in GitHub Desktop.
Nagios notify-email custom script
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' | |
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] | |
nodemailer = require 'nodemailer' | |
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 | |
" | |
html = "Nagios requires your attention.\n | |
\n | |
Hostname: " + argvObject.hostname + "<br> | |
service: " + argvObject.service + "<br> | |
ip: " + argvObject.ip + "<br> | |
notify: " + argvObject.notify_type + "<br> | |
status: " + argvObject.status + "<br> | |
date: " + argvObject.date + "<br> | |
output: " + argvObject.output + "<br> | |
" | |
mailOptions = | |
from: "Nagios <[email protected]>" | |
to: "[email protected]" | |
subject: "Hello, notification from nagios" | |
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