forked from outlyerapp/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpingdom.rb
More file actions
119 lines (110 loc) · 2.94 KB
/
pingdom.rb
File metadata and controls
119 lines (110 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#! /usr/bin/env ruby
# Author: Russell-IO https://github.com/Russell-IO
# either use a command line arguements, or optionally a config file for check identifier
# This means you can deploy a yaml config file to allow you to have one check etc.
# exmaple ./pingdom.rb --execute --account pingdom@you.com --password abc123 --token def456 --config /etc/config.yml
require 'main'
require 'yaml'
require 'httparty'
Main {
option('execute'){
argument :optional
description 'execute the check'
}
option('hostname'){
argument :optional
description 'Specify The Stack to check'
}
option('username'){
argument :optional
description 'Specify the Username'
}
option('password'){
argument :optional
description 'Specify the Password'
}
option('authtoken'){
argument :optional
description 'Specify the authtoken'
}
option('account'){
argument :optional
description 'Specify the account'
}
option('url'){
argument :optional
defaults 'https://api.pingdom.com/api/2.0/checks'
description 'Optionally override the pingdom endpoint'
}
option('config'){
argument :optional
description 'Path of Config file'
}
def run
if params['execute'].value == true
# Capture a HUP signal and act accordingly
Signal.trap("HUP") { Process.kill("HUP"); Process.wait }
# Set variables from arguements
hostname = "#{params['hostname'].value}"
username = "#{params['username'].value}"
password = "#{params['password'].value}"
authtoken = "#{params['authtoken'].value}"
account = "#{params['account'].value}"
url = "#{params['url'].value}"
# update params from config file if specified
if params['config'].value != "false"
config = YAML.load_file("#{params['config'].value}")
hostname = "#{config['hostname']}"
end
#Build response headers
auth =
{
:username => "#{username}",
:password => "#{password}"
}
headers =
{
"App-Key" => authtoken,
"Account-Email" => account
}
# Execute the api request
response =
HTTParty.get(
"#{url}?tags=dataloop",
:basic_auth => auth,
:headers => headers
)
# Select the HTTPS request for the stack in question
stack = response['checks'].select { |hash| hash['hostname'] == "#{hostname}" }
https = stack
# Set the response vars
status = https.first['status']
lrtime = https.first['lastresponsetime']
# Build the nagios response
case status
when "up"
puts "OK | responsetime=#{lrtime};;;;"
exit_status 0
exit_success!
when "down"
puts "DOWN | responsetime=#{lrtime};;;;"
exit_status 2
exit_failure!
when "unconfirmed_down"
puts "UNCONFIRMED | responsetime=#{lrtime};;;;"
exit_status 1
exit_failure!
when "paused"
puts "PAUSED | responsetime=#{lrtime};;;;"
exit_status 1
exit_failure!
else
puts "UNKNOWN | responsetime=#{lrtime};;;;"
exit_status 3
exit_failure!
end
else
puts "--execute hasn't been specified check --help"
end
end
}