hubot-scripts
Version:
Allows you to opt in to a variety of scripts
58 lines (48 loc) • 1.94 kB
text/coffeescript
# Description:
# Show uptime status of sites monitored by UptimeRobot.
#
# Dependencies:
# None
#
# Configuration:
# HUBOT_UPTIMEROBOT_APIKEY
#
# Commands:
# hubot what is the uptime of the monitored sites? - Show the status of the monitored sites
# hubot start monitoring the http uptime of <url> - Instructs uptime robot to monitor the <url>
#
# Author:
# lukesmith
module.exports = (robot) ->
apikey = process.env.HUBOT_UPTIMEROBOT_APIKEY
robot.respond /what is the uptime of the monitored sites?/i, (msg) ->
msg.http("http://api.uptimerobot.com/getMonitors")
.query({ apiKey: apikey, logs: 0, format: "json", noJsonCallback: 1 })
.get() (err, res, body) ->
if err
msg.send "Uptime robot says: #{err}"
return
response = JSON.parse(body)
if response.stat is "ok"
for monitor in response.monitors.monitor
status = ""
switch monitor.status
when "1" then status = "paused"
when "2" then status = "up"
when "8" then status = "seems down"
when "9" then status = "down"
else status = "unknown"
msg.send "#{monitor.friendlyname}: has an uptime of #{monitor.alltimeuptimeratio}% and current status of #{status}"
else if response.stat is "fail"
msg.send "Uhoh, #{response.message}";
robot.respond /start monitoring the http uptime of (.*)$/i, (msg) ->
monitorUrl = msg.match[1]
monitorFriendlyName = msg.match[1]
msg.http("http://api.uptimerobot.com/newMonitor")
.query({ apiKey: apikey, monitorFriendlyName: monitorFriendlyName, monitorURL: monitorUrl, monitorType: 1, format: "json", noJsonCallback: 1 })
.get() (err, res, body) ->
response = JSON.parse(body)
if response.stat is "ok"
msg.send "done"
if response.stat is "fail"
msg.send "#{response.message}"