Skip to content

Instantly share code, notes, and snippets.

@mikekunze
Created July 14, 2012 16:02
Show Gist options
  • Save mikekunze/3111907 to your computer and use it in GitHub Desktop.
Save mikekunze/3111907 to your computer and use it in GitHub Desktop.
Nagios notify-email custom script
#!/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:&nbsp;&nbsp;&nbsp;&nbsp;" + argvObject.hostname + "<br>
service: &nbsp;&nbsp;&nbsp;&nbsp;" + argvObject.service + "<br>
ip: &nbsp;&nbsp;&nbsp;&nbsp;" + argvObject.ip + "<br>
notify: &nbsp;&nbsp;&nbsp;&nbsp;" + argvObject.notify_type + "<br>
status: &nbsp;&nbsp;&nbsp;&nbsp;" + argvObject.status + "<br>
date: &nbsp;&nbsp;&nbsp;&nbsp;" + argvObject.date + "<br>
output: &nbsp;&nbsp;&nbsp;&nbsp;" + 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