nagios-herald 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +9 -0
- data/CHANGELOG.md +11 -0
- data/CONTRIBUTING.md +28 -0
- data/Gemfile +5 -0
- data/LICENSE +21 -0
- data/README.md +94 -0
- data/Rakefile +9 -0
- data/bin/draw_stack_bars +76 -0
- data/bin/dump_nagios_env.sh +25 -0
- data/bin/get_ganglia_graph +82 -0
- data/bin/get_graph +50 -0
- data/bin/get_graphite_graph +58 -0
- data/bin/nagios-herald +6 -0
- data/bin/splunk_alert_frequency +54 -0
- data/contrib/nrpe-plugins/check_cpu_stats.sh +186 -0
- data/contrib/nrpe-plugins/check_disk.sh +34 -0
- data/contrib/nrpe-plugins/check_mem.pl +181 -0
- data/contrib/nrpe-plugins/nrpe-plugin-examples.md +11 -0
- data/docs/config.md +62 -0
- data/docs/example_alerts.md +48 -0
- data/docs/formatters.md +180 -0
- data/docs/helpers.md +12 -0
- data/docs/images/cpu_no_context.png +0 -0
- data/docs/images/cpu_with_context.png +0 -0
- data/docs/images/disk_space_no_context.png +0 -0
- data/docs/images/disk_space_with_context.png +0 -0
- data/docs/images/memory_high_no_context.png +0 -0
- data/docs/images/memory_high_with_context.png +0 -0
- data/docs/images/nagios-herald-formatter-content-example.png +0 -0
- data/docs/images/nagios-herald.png +0 -0
- data/docs/images/stack-bars.png +0 -0
- data/docs/images/vanilla-nagios.png +0 -0
- data/docs/messages.md +16 -0
- data/docs/nagios-config.md +74 -0
- data/docs/tools.md +79 -0
- data/etc/config.yml.example +14 -0
- data/etc/readme.md +2 -0
- data/lib/nagios-herald/config.rb +25 -0
- data/lib/nagios-herald/executor.rb +265 -0
- data/lib/nagios-herald/formatter_loader.rb +82 -0
- data/lib/nagios-herald/formatters/base.rb +524 -0
- data/lib/nagios-herald/formatters/check_cpu.rb +71 -0
- data/lib/nagios-herald/formatters/check_disk.rb +143 -0
- data/lib/nagios-herald/formatters/check_logstash.rb +155 -0
- data/lib/nagios-herald/formatters/check_memory.rb +42 -0
- data/lib/nagios-herald/formatters/example.rb +19 -0
- data/lib/nagios-herald/formatters.rb +1 -0
- data/lib/nagios-herald/helpers/ganglia_graph.rb +99 -0
- data/lib/nagios-herald/helpers/graphite_graph.rb +85 -0
- data/lib/nagios-herald/helpers/logstash_query.rb +125 -0
- data/lib/nagios-herald/helpers/splunk_alert_frequency.rb +170 -0
- data/lib/nagios-herald/helpers/splunk_query.rb +119 -0
- data/lib/nagios-herald/helpers/url_image.rb +76 -0
- data/lib/nagios-herald/helpers.rb +5 -0
- data/lib/nagios-herald/logging.rb +48 -0
- data/lib/nagios-herald/message_loader.rb +40 -0
- data/lib/nagios-herald/messages/base.rb +56 -0
- data/lib/nagios-herald/messages/email.rb +150 -0
- data/lib/nagios-herald/messages/irc.rb +58 -0
- data/lib/nagios-herald/messages/pager.rb +75 -0
- data/lib/nagios-herald/messages.rb +3 -0
- data/lib/nagios-herald/test_helpers/base_test_case.rb +82 -0
- data/lib/nagios-herald/util.rb +45 -0
- data/lib/nagios-herald/version.rb +3 -0
- data/lib/nagios-herald.rb +7 -0
- data/lib/stackbars/__init__.py +0 -0
- data/lib/stackbars/chart_utils.py +25 -0
- data/lib/stackbars/grouped_stackbars.py +97 -0
- data/lib/stackbars/pilfonts/Tahoma.ttf +0 -0
- data/lib/stackbars/pilfonts/aerial.ttf +0 -0
- data/lib/stackbars/pilfonts/arial_black.ttf +0 -0
- data/lib/stackbars/stackbar.py +100 -0
- data/nagios-herald.gemspec +33 -0
- data/test/env_files/check_cpu_idle.CRITICAL +199 -0
- data/test/env_files/check_cpu_iowait.WARNING +199 -0
- data/test/env_files/check_disk.CRITICAL +197 -0
- data/test/env_files/check_disk.CRITICAL_ICINGA +197 -0
- data/test/env_files/check_disk.RECOVERY +197 -0
- data/test/env_files/check_memory.CRITICAL +197 -0
- data/test/env_files/nagios_vars.EXAMPLE +197 -0
- data/test/unit/test_config.rb +31 -0
- data/test/unit/test_executor.rb +65 -0
- data/test/unit/test_formatter_base.rb +131 -0
- data/test/unit/test_formatter_check_cpu_idle_critical.rb +135 -0
- data/test/unit/test_formatter_check_memory.rb +135 -0
- data/test/unit/test_icinga_variables.rb +31 -0
- data/test/unit/test_logging.rb +35 -0
- data/test/unit/test_message_email.rb +69 -0
- data/test/unit/test_message_pager.rb +69 -0
- metadata +204 -0
@@ -0,0 +1,197 @@
|
|
1
|
+
NAGIOS_SERVICESTATE=CRITICAL
|
2
|
+
NAGIOS_HOSTNOTIFICATIONNUMBER=0
|
3
|
+
NAGIOS_HOSTNOTIFICATIONID=0
|
4
|
+
NAGIOS_ARG8=
|
5
|
+
NAGIOS_SERVICEACKAUTHOR=ops
|
6
|
+
NAGIOS_COMMANDFILE=/usr/nagios/var/rw/nagios.cmd
|
7
|
+
NAGIOS_ARG9=
|
8
|
+
NAGIOS_HOSTADDRESS=10.101.194.198
|
9
|
+
NAGIOS_LASTHOSTDOWN=0
|
10
|
+
NAGIOS_LASTSERVICEWARNING=0
|
11
|
+
NAGIOS_TEMPPATH=/tmp/nagios
|
12
|
+
NAGIOS_TOTALHOSTSERVICESCRITICAL=1
|
13
|
+
NAGIOS_HOSTACKAUTHOR=
|
14
|
+
NAGIOS_TEMPFILE=/usr/nagios/var/nagios.tmp
|
15
|
+
NAGIOS_NOTIFICATIONAUTHOR=
|
16
|
+
NAGIOS_ISVALIDTIME=
|
17
|
+
TERM=screen-256color
|
18
|
+
NAGIOS_SERVICEGROUPALIAS=
|
19
|
+
NAGIOS_ARG28=
|
20
|
+
NAGIOS_HOSTEXECUTIONTIME=4.006
|
21
|
+
NAGIOS_SERVICEACKCOMMENT=
|
22
|
+
NAGIOS_ARG29=
|
23
|
+
NAGIOS_LOGFILE=/usr/nagios/var/nagios.log
|
24
|
+
NAGIOS_TOTALHOSTSUNREACHABLEUNHANDLED=
|
25
|
+
NAGIOS_SERVICEACKAUTHORNAME=
|
26
|
+
NAGIOS_NEXTVALIDTIME=
|
27
|
+
NAGIOS_ARG26=
|
28
|
+
NAGIOS_TIMET=1368738398
|
29
|
+
NAGIOS_HOSTGROUPNAMES=test
|
30
|
+
NAGIOS_MAXSERVICEATTEMPTS=3
|
31
|
+
NAGIOS_ARG1=
|
32
|
+
NAGIOS_ARG27=
|
33
|
+
NAGIOS_HOSTSTATEID=0
|
34
|
+
NAGIOS_LASTSERVICECRITICAL=1368738397
|
35
|
+
NAGIOS_ARG2=
|
36
|
+
NAGIOS_ARG24=
|
37
|
+
NAGIOS_EVENTSTARTTIME=1367776508
|
38
|
+
NAGIOS_ARG3=
|
39
|
+
NAGIOS_ARG25=
|
40
|
+
NAGIOS_HOSTACKCOMMENT=
|
41
|
+
NAGIOS_SERVICENOTES=
|
42
|
+
NAGIOS_SERVICEGROUPNOTESURL=
|
43
|
+
NAGIOS_HOSTGROUPMEMBERS=web.example.com
|
44
|
+
NAGIOS_NOTIFICATIONCOMMENT=
|
45
|
+
NAGIOS_ARG4=
|
46
|
+
NAGIOS_ARG22=
|
47
|
+
NAGIOS_TOTALHOSTPROBLEMSUNHANDLED=
|
48
|
+
NAGIOS_HOSTEVENTID=0
|
49
|
+
NAGIOS_ARG5=
|
50
|
+
NAGIOS_ARG23=
|
51
|
+
NAGIOS_TOTALHOSTSERVICESOK=0
|
52
|
+
NAGIOS_ARG6=
|
53
|
+
NAGIOS_ARG20=
|
54
|
+
NAGIOS_TIME=21:06:38
|
55
|
+
NAGIOS_HOSTACTIONURL=
|
56
|
+
NAGIOS_CONTACTGROUPALIAS=People who care about continuous integration servers
|
57
|
+
NAGIOS_ARG7=
|
58
|
+
NAGIOS_ARG21=
|
59
|
+
NAGIOS_SERVICEPERFDATA=/=31269MB;36287;2015;0;40319 /dev/shm=82MB;2236;124;0;2485 /data=44700860MB;54876558;3048697;0;60973954
|
60
|
+
NAGIOS_LASTSERVICESTATE=CRITICAL
|
61
|
+
NAGIOS_CONTACTNAME=ops
|
62
|
+
NAGIOS_HOSTPERCENTCHANGE=0.00
|
63
|
+
NAGIOS_HOSTGROUPALIAS=Test Host Group
|
64
|
+
LD_LIBRARY_PATH=:/usr/local/lib
|
65
|
+
NAGIOS_RESOURCEFILE=/usr/nagios/etc/resource.cfg
|
66
|
+
NAGIOS_CONTACTGROUPMEMBERS=ops
|
67
|
+
NAGIOS_ARG19=
|
68
|
+
NAGIOS_SERVICECHECKTYPE=ACTIVE
|
69
|
+
NAGIOS_ARG18=
|
70
|
+
NAGIOS_SERVICEATTEMPT=3
|
71
|
+
NAGIOS_TOTALHOSTSDOWNUNHANDLED=
|
72
|
+
NAGIOS_HOSTDOWNTIME=0
|
73
|
+
NAGIOS_HOSTCHECKCOMMAND=check-host-alive
|
74
|
+
NAGIOS_TOTALHOSTSERVICESUNKNOWN=0
|
75
|
+
NAGIOS_SERVICEGROUPNAME=
|
76
|
+
NAGIOS_SERVICEGROUPACTIONURL=
|
77
|
+
NAGIOS_LASTSERVICESTATECHANGE=1368738086
|
78
|
+
NAGIOS_RETENTIONDATAFILE=/usr/nagios/var/retention.dat
|
79
|
+
NAGIOS_TOTALSERVICEPROBLEMSUNHANDLED=
|
80
|
+
NAGIOS_LASTSERVICEEVENTID=8
|
81
|
+
NAGIOS_TOTALHOSTSERVICES=1
|
82
|
+
NAGIOS_CONTACTGROUPNAME=test
|
83
|
+
NAGIOS_ARG13=
|
84
|
+
NAGIOS_CONTACTPAGER=
|
85
|
+
NAGIOS_NOTIFICATIONTYPE=PROBLEM
|
86
|
+
NAGIOS_LASTSERVICEPROBLEMID=3
|
87
|
+
NAGIOS_ARG12=
|
88
|
+
NAGIOS_LASTHOSTCHECK=1368738363
|
89
|
+
NAGIOS_ADMINPAGER=ops@example.com
|
90
|
+
NAGIOS_SERVICECHECKCOMMAND=check_nrpe!check_disk
|
91
|
+
NAGIOS_TOTALSERVICESWARNING=
|
92
|
+
NAGIOS_LASTHOSTSTATEID=0
|
93
|
+
NAGIOS_ARG11=
|
94
|
+
NAGIOS_HOSTPERFDATA=rta=0.496000ms;3000.000000;5000.000000;0.000000 pl=0%;80;100;0
|
95
|
+
NAGIOS_LASTSERVICEOK=1368737846
|
96
|
+
NAGIOS_TOTALHOSTSDOWN=
|
97
|
+
NAGIOS_SERVICENOTIFICATIONNUMBER=1
|
98
|
+
NAGIOS_CONTACTGROUPNAMES=test
|
99
|
+
NAGIOS_ARG10=
|
100
|
+
NAGIOS_SERVICEPERCENTCHANGE=6.25
|
101
|
+
NAGIOS_TOTALHOSTPROBLEMS=
|
102
|
+
NAGIOS_TOTALSERVICESOK=
|
103
|
+
NAGIOS_TOTALHOSTSERVICESWARNING=0
|
104
|
+
NAGIOS_ARG17=
|
105
|
+
PATH=/sbin:/usr/sbin:/bin:/usr/bin
|
106
|
+
NAGIOS_HOSTOUTPUT=PING OK - Packet loss = 0%, RTA = 0.50 ms
|
107
|
+
NAGIOS_NOTIFICATIONRECIPIENTS=ops
|
108
|
+
NAGIOS_ARG16=
|
109
|
+
NAGIOS_MAXHOSTATTEMPTS=1
|
110
|
+
NAGIOS_ARG15=
|
111
|
+
NAGIOS_TOTALHOSTSUNREACHABLE=
|
112
|
+
NAGIOS_TOTALSERVICESWARNINGUNHANDLED=
|
113
|
+
NAGIOS_ARG14=
|
114
|
+
NAGIOS_STATUSDATAFILE=/usr/nagios/var/status.dat
|
115
|
+
NAGIOS_TOTALSERVICESUNKNOWN=
|
116
|
+
NAGIOS_LASTHOSTPROBLEMID=0
|
117
|
+
NAGIOS_ARG31=
|
118
|
+
PWD=/
|
119
|
+
NAGIOS_SHORTDATETIME=05-16-2013 21:06:38
|
120
|
+
NAGIOS_HOSTSTATE=UP
|
121
|
+
NAGIOS_LASTHOSTUP=1368738368
|
122
|
+
NAGIOS_SERVICEGROUPNOTES=
|
123
|
+
NAGIOS_ARG30=
|
124
|
+
NAGIOS_SERVICEPERFDATAFILE=
|
125
|
+
NAGIOS_ARG32=
|
126
|
+
LANG=en_US.UTF-8
|
127
|
+
NAGIOS_CONTACTALIAS=Ops Engineer
|
128
|
+
NAGIOS_HOSTNOTESURL=
|
129
|
+
NAGIOS_SERVICELATENCY=0.189
|
130
|
+
NAGIOS_TOTALSERVICESCRITICAL=
|
131
|
+
NAGIOS_SERVICEDOWNTIME=0
|
132
|
+
NAGIOS_SERVICEGROUPNAMES=
|
133
|
+
NAGIOS_DATE=05-16-2013
|
134
|
+
NAGIOS_SERVICEEVENTID=9
|
135
|
+
NAGIOS_HOSTACKAUTHORALIAS=
|
136
|
+
NAGIOS_NOTIFICATIONAUTHORALIAS=
|
137
|
+
NAGIOS_SERVICEDURATION=0d 0h 5m 12s
|
138
|
+
NAGIOS_HOSTSTATETYPE=HARD
|
139
|
+
NAGIOS_SERVICEPROBLEMID=4
|
140
|
+
NAGIOS_HOSTCHECKTYPE=ACTIVE
|
141
|
+
NAGIOS_HOSTGROUPNOTES=
|
142
|
+
NAGIOS_LASTSERVICECHECK=1368738397
|
143
|
+
NAGIOS_ADMINEMAIL=ops@example.com
|
144
|
+
NAGIOS_OBJECTCACHEFILE=/usr/nagios/var/objects.cache
|
145
|
+
NAGIOS_HOSTLATENCY=0.163
|
146
|
+
NAGIOS_HOSTGROUPACTIONURL=
|
147
|
+
SHLVL=4
|
148
|
+
NAGIOS_LONGDATETIME=Thu May 16 21:06:38 UTC 2013
|
149
|
+
NAGIOS_HOSTDISPLAYNAME=web.example.com
|
150
|
+
NAGIOS_SERVICESTATEID=2
|
151
|
+
NAGIOS_SERVICENOTESURL=
|
152
|
+
NAGIOS_TOTALSERVICEPROBLEMS=
|
153
|
+
NAGIOS_HOSTPROBLEMID=0
|
154
|
+
NAGIOS_CONTACTADDRESS0=
|
155
|
+
NAGIOS_HOSTDURATIONSEC=966190
|
156
|
+
NAGIOS_TOTALSERVICESUNKNOWNUNHANDLED=
|
157
|
+
NAGIOS_LASTHOSTSTATE=UP
|
158
|
+
NAGIOS_CONTACTADDRESS1=
|
159
|
+
NAGIOS_SERVICEEXECUTIONTIME=0.028
|
160
|
+
NAGIOS_TOTALSERVICESCRITICALUNHANDLED=
|
161
|
+
NAGIOS_CONTACTADDRESS2=
|
162
|
+
NAGIOS_LONGHOSTOUTPUT=
|
163
|
+
NAGIOS_SERVICEGROUPMEMBERS=
|
164
|
+
NAGIOS_CONTACTADDRESS3=
|
165
|
+
NAGIOS_SERVICEDURATIONSEC=312
|
166
|
+
NAGIOS_CONTACTADDRESS4=
|
167
|
+
NAGIOS_HOSTGROUPNOTESURL=
|
168
|
+
NAGIOS_CONTACTADDRESS5=
|
169
|
+
NAGIOS_SERVICEOUTPUT=DISK CRITICAL - free space: / 7002 MB (18% inode 60%): /data 16273093 MB (26% inode 99%):
|
170
|
+
NAGIOS_NOTIFICATIONNUMBER=1
|
171
|
+
NAGIOS_HOSTDURATION=11d 4h 23m 10s
|
172
|
+
NAGIOS_MAINCONFIGFILE=/usr/nagios/etc/nagios.cfg
|
173
|
+
NAGIOS_CONTACTEMAIL=ops@example.com
|
174
|
+
NAGIOS_SERVICESTATETYPE=HARD
|
175
|
+
NAGIOS_LASTHOSTUNREACHABLE=0
|
176
|
+
NAGIOS_LONGSERVICEOUTPUT=\nTHRESHOLDS - WARNING:15%;CRITICAL:20%;\n\nFilesystem Size Used Avail Use% Mounted on\n/dev/vda 40G 31G 6.9G 82% /\ntmpfs 2.5G 83M 2.4G 4% /dev/shm\nnfs.example.example.com:/mnt/user/homes\n 59T 43T 16T 74% /data\n
|
177
|
+
NAGIOS_HOSTATTEMPT=1
|
178
|
+
NAGIOS_HOSTNOTES=
|
179
|
+
NAGIOS_SERVICEISVOLATILE=0
|
180
|
+
NAGIOS_SERVICEACTIONURL=http://runbook.example.com/disk_space_alerts.html
|
181
|
+
NAGIOS_SERVICEDISPLAYNAME=Disk Space
|
182
|
+
NAGIOS_TOTALHOSTSUP=
|
183
|
+
NAGIOS_LASTHOSTSTATECHANGE=1367772208
|
184
|
+
NAGIOS_LASTSERVICEUNKNOWN=0
|
185
|
+
NAGIOS_HOSTPERFDATAFILE=
|
186
|
+
NAGIOS_LASTHOSTEVENTID=0
|
187
|
+
NAGIOS_HOSTACKAUTHORNAME=
|
188
|
+
NAGIOS_NOTIFICATIONAUTHORNAME=
|
189
|
+
NAGIOS_HOSTALIAS=web.example.com
|
190
|
+
NAGIOS_SERVICEDESC=Disk Space
|
191
|
+
NAGIOS_HOSTGROUPNAME=test
|
192
|
+
NAGIOS_PROCESSSTARTTIME=1367776508
|
193
|
+
NAGIOS_HOSTNAME=web.example.com
|
194
|
+
NAGIOS_SERVICENOTIFICATIONID=45
|
195
|
+
NAGIOS_SERVICEACKAUTHORALIAS=
|
196
|
+
NAGIOS_LASTSERVICESTATEID=2
|
197
|
+
_=/bin/env
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
|
3
|
+
# I assume cat'ing to the LOAD path goes away when we're a real gem.
|
4
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
5
|
+
require 'nagios-herald'
|
6
|
+
require 'nagios-herald/config'
|
7
|
+
|
8
|
+
# Test the Config module.
|
9
|
+
class TestConfig < MiniTest::Unit::TestCase
|
10
|
+
|
11
|
+
# Initial setup before we execute tests
|
12
|
+
def setup
|
13
|
+
@options = {}
|
14
|
+
@options['config_file'] = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'etc', 'config.yml.example'))
|
15
|
+
@options['message_type'] = "pager"
|
16
|
+
end
|
17
|
+
|
18
|
+
def teardown
|
19
|
+
end
|
20
|
+
|
21
|
+
# Make sure we can load the config and read values from it.
|
22
|
+
# Read values from command-line options and the config file.
|
23
|
+
def test_load_config
|
24
|
+
NagiosHerald::Config.load(@options)
|
25
|
+
assert_equal "pager", NagiosHerald::Config.config['message_type'] # Command line
|
26
|
+
assert_equal "ganglia.example.com", NagiosHerald::Config.config['servers']['ganglia'] # Config file
|
27
|
+
assert_equal "splunkuser", NagiosHerald::Config.config['splunk']['username'] # Config file
|
28
|
+
assert_equal "http://logstash.example.com:9200", NagiosHerald::Config.config['logstash']['url'] # Config file
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
|
3
|
+
# I assume cat'ing to the LOAD path goes away when we're a real gem.
|
4
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
5
|
+
require 'nagios-herald'
|
6
|
+
require 'nagios-herald/executor'
|
7
|
+
|
8
|
+
# Test the Executor class.
|
9
|
+
class TestExecutor < MiniTest::Unit::TestCase
|
10
|
+
include NagiosHerald::Util
|
11
|
+
|
12
|
+
# initial setup before we execute tests
|
13
|
+
def setup
|
14
|
+
@executor = NagiosHerald::Executor.new
|
15
|
+
@options = {}
|
16
|
+
@options[:env] = File.join(File.dirname(__FILE__), '..', 'env_files', 'nagios_vars.EXAMPLE')
|
17
|
+
end
|
18
|
+
|
19
|
+
def teardown
|
20
|
+
end
|
21
|
+
|
22
|
+
# We expect a NagiosHerald::Executor object.
|
23
|
+
def test_new_executor
|
24
|
+
assert_instance_of NagiosHerald::Executor, @executor
|
25
|
+
end
|
26
|
+
|
27
|
+
# Make sure we can load an environment file and read some env variables.
|
28
|
+
# We'll use Util::get_nagios_var just like Executor does.
|
29
|
+
def test_load_env_file
|
30
|
+
@executor.load_env_from_file(@options[:env])
|
31
|
+
assert_equal "ops@example.com", get_nagios_var('NAGIOS_CONTACTEMAIL')
|
32
|
+
assert_equal "PROBLEM", get_nagios_var('NAGIOS_NOTIFICATIONTYPE')
|
33
|
+
end
|
34
|
+
|
35
|
+
# Get the file names of each of the formatter classes and confirm they load properly.
|
36
|
+
# This helps ensure formatters are named and subclassed properly.
|
37
|
+
def test_load_formatters
|
38
|
+
formatter_dir = File.join(File.dirname(__FILE__), '..', '..', 'lib', 'nagios-herald', 'formatters')
|
39
|
+
formatter_class_files = Dir["#{formatter_dir}/*.rb"]
|
40
|
+
@executor.load_formatters
|
41
|
+
formatter_class_files.each do |formatter_class_file|
|
42
|
+
class_file = File.basename(formatter_class_file, '.rb') # strip the extension
|
43
|
+
next if class_file.eql?('base') # base.rb doesn't get loaded
|
44
|
+
assert NagiosHerald::Formatter.formatters.has_key?(class_file), "'#{formatter_dir}/#{class_file}.rb' was not loaded. "\
|
45
|
+
"Check that it's named and subclassed properly.\n"\
|
46
|
+
"See https://github.com/etsy/nagios-herald/blob/master/docs/formatters.md for help."
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Get the file names of each of the message classes and confirm they load properly.
|
51
|
+
# This helps ensure messages are named and subclassed properly.
|
52
|
+
def test_load_messages
|
53
|
+
message_dir = File.join(File.dirname(__FILE__), '..', '..', 'lib', 'nagios-herald', 'messages')
|
54
|
+
message_class_files = Dir["#{message_dir}/*.rb"]
|
55
|
+
@executor.load_messages
|
56
|
+
message_class_files.each do |message_class_file|
|
57
|
+
class_file = File.basename(message_class_file, '.rb') # strip the extension
|
58
|
+
next if class_file.eql?('base') # base.rb doesn't get loaded
|
59
|
+
assert NagiosHerald::Message.message_types.has_key?(class_file), "'#{message_dir}/#{class_file}.rb' was not loaded. "\
|
60
|
+
"Check that it's named and subclassed properly.\n"\
|
61
|
+
"See https://github.com/etsy/nagios-herald/blob/master/docs/messages.md for help."
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
|
3
|
+
# I assume cat'ing to the LOAD path goes away when we're a real gem.
|
4
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
5
|
+
require 'nagios-herald'
|
6
|
+
require 'nagios-herald/config'
|
7
|
+
require 'nagios-herald/executor'
|
8
|
+
require 'nagios-herald/formatters/base'
|
9
|
+
|
10
|
+
# Test Formatter::Base.
|
11
|
+
class TestFormatterBase < MiniTest::Unit::TestCase
|
12
|
+
|
13
|
+
# TODO: We need a similar set of tests for RECOVERY emails.
|
14
|
+
# Initial setup before we execute tests
|
15
|
+
def setup
|
16
|
+
@options = {}
|
17
|
+
@options[:message_type] = 'EMAIL'
|
18
|
+
@options[:nagios_url] = "http://nagios.example.com"
|
19
|
+
@formatter = NagiosHerald::Formatter.new(@options)
|
20
|
+
env_file = File.join(File.dirname(__FILE__), '..', 'env_files', 'nagios_vars.EXAMPLE')
|
21
|
+
NagiosHerald::Executor.new.load_env_from_file(env_file) # load an env file for testing
|
22
|
+
end
|
23
|
+
|
24
|
+
def teardown
|
25
|
+
# make certain we don't leave tons of empty temp dirs behind
|
26
|
+
@formatter.clean_sandbox
|
27
|
+
end
|
28
|
+
|
29
|
+
# Test that we have a new NagiosHerald::Formatter object.
|
30
|
+
def test_new_formatter
|
31
|
+
assert_instance_of NagiosHerald::Formatter, @formatter
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_add_content_basic
|
35
|
+
@formatter.add_text('test_add_content', 'This is test text')
|
36
|
+
assert_equal 'This is test text', @formatter.content[:text][:test_add_content]
|
37
|
+
@formatter.add_html('test_add_content', '<b>This is test HTML</b>')
|
38
|
+
assert_equal '<b>This is test HTML</b>', @formatter.content[:html][:test_add_content]
|
39
|
+
@formatter.generate_subject
|
40
|
+
assert_equal "PROBLEM Service web.example.com/Disk Space is CRITICAL", @formatter.content[:subject]
|
41
|
+
attachment_name = "#{@formatter.sandbox}/cat.gif"
|
42
|
+
@formatter.add_attachment(attachment_name)
|
43
|
+
assert @formatter.content[:attachments].include?(attachment_name), "Failed to attach #{attachment_name} to content hash."
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_action_url
|
47
|
+
@formatter.action_url
|
48
|
+
assert_equal "<b>Action URL</b>: http://runbook.example.com/disk_space_alerts.html<br><br>", @formatter.content[:html][:action_url]
|
49
|
+
assert_equal "Action URL: http://runbook.example.com/disk_space_alerts.html\n\n", @formatter.content[:text][:action_url]
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_host_info
|
53
|
+
@formatter.host_info
|
54
|
+
assert_equal "<br><b>Host</b>: web.example.com <b>Service</b>: Disk Space<br/><br>", @formatter.content[:html][:host_info]
|
55
|
+
assert_equal "Host: web.example.com Service: Disk Space\n\n", @formatter.content[:text][:host_info]
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_state_info
|
59
|
+
@formatter.state_info
|
60
|
+
assert_equal "State is now: <b><font style='color:red'>CRITICAL</font></b> for <b>0d 0h 5m 12s</b> (was CRITICAL) after <b>3 / 3</b> checks<br/><br>", @formatter.content[:html][:state_info]
|
61
|
+
assert_equal "State is now: CRITICAL for 0d 0h 5m 12s (was CRITICAL) after 3 / 3 checks\n\n", @formatter.content[:text][:state_info]
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_notification_info
|
65
|
+
@formatter.notification_info
|
66
|
+
assert_equal "Notification sent at: Thu May 16 21:06:38 UTC 2013 (notification number 1)<br><br>", @formatter.content[:html][:notification_info]
|
67
|
+
assert_equal "Notification sent at: Thu May 16 21:06:38 UTC 2013 (notification number 1)\n\n", @formatter.content[:text][:notification_info]
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_additional_info
|
71
|
+
@formatter.additional_info
|
72
|
+
assert_equal "<b>Additional Info</b>: DISK CRITICAL - free space: / 7002 MB (18% inode 60%): /data 16273093 MB (26% inode 99%):<br><br>", @formatter.content[:html][:additional_info]
|
73
|
+
assert_equal "Additional Info: DISK CRITICAL - free space: / 7002 MB (18% inode 60%): /data 16273093 MB (26% inode 99%):\n\n", @formatter.content[:text][:additional_info]
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_additional_details
|
77
|
+
@formatter.additional_details
|
78
|
+
assert_equal "<b>Additional Details</b>: <pre>\nTHRESHOLDS - WARNING:15%;CRITICAL:20%;\n\nFilesystem Size Used Avail Use% Mounted on\n/dev/vda 40G 31G 6.9G 82% /\ntmpfs 2.5G 83M 2.4G 4% /dev/shm\nnfs.example.example.com:/mnt/user/homes\n 59T 43T 16T 74% /data\n</pre><br><br>", @formatter.content[:html][:additional_details]
|
79
|
+
assert_equal "Additional Details: \nTHRESHOLDS - WARNING:15%;CRITICAL:20%;\n\nFilesystem Size Used Avail Use% Mounted on\n/dev/vda 40G 31G 6.9G 82% /\ntmpfs 2.5G 83M 2.4G 4% /dev/shm\nnfs.example.example.com:/mnt/user/homes\n 59T 43T 16T 74% /data\n\n", @formatter.content[:text][:additional_details]
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_notes
|
83
|
+
@formatter.notes
|
84
|
+
# There are no notes in the example environment variables.
|
85
|
+
assert_equal "", @formatter.content[:html][:notes]
|
86
|
+
assert_equal "", @formatter.content[:text][:notes]
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_action_url
|
90
|
+
@formatter.action_url
|
91
|
+
assert_equal "<b>Action URL</b>: http://runbook.example.com/disk_space_alerts.html<br><br>", @formatter.content[:html][:action_url]
|
92
|
+
assert_equal "Action URL: http://runbook.example.com/disk_space_alerts.html\n\n", @formatter.content[:text][:action_url]
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_short_state_detail
|
96
|
+
@formatter.short_state_detail
|
97
|
+
assert_equal "DISK CRITICAL - free space: / 7002 MB (18% inode 60%): /data 16273093 MB (26% inode 99%):<br>", @formatter.content[:html][:short_state_detail]
|
98
|
+
assert_equal "DISK CRITICAL - free space: / 7002 MB (18% inode 60%): /data 16273093 MB (26% inode 99%):\n", @formatter.content[:text][:short_state_detail]
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_recipients_email_link
|
102
|
+
@formatter.recipients_email_link
|
103
|
+
assert_equal "Sent to ops<br><br>", @formatter.content[:html][:recipients_email_link]
|
104
|
+
assert_equal "Sent to ops\n\n", @formatter.content[:text][:recipients_email_link]
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_ack_info
|
108
|
+
@formatter.ack_info
|
109
|
+
assert_equal "At Thu May 16 21:06:38 UTC 2013 ops acknowledged web.example.com/Disk Space.<br><br>Comment: ", @formatter.content[:html][:ack_info]
|
110
|
+
assert_equal "At Thu May 16 21:06:38 UTC 2013 ops acknowledged web.example.com/Disk Space.\n\nComment: ", @formatter.content[:text][:ack_info]
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_short_ack_info
|
114
|
+
@formatter.short_ack_info
|
115
|
+
assert_equal "ops ack'd Disk Space on web.example.com.<br>", @formatter.content[:html][:short_ack_info]
|
116
|
+
assert_equal "ops ack'd Disk Space on web.example.com.\n", @formatter.content[:text][:short_ack_info]
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_alert_ack_url
|
120
|
+
@formatter.alert_ack_url
|
121
|
+
assert_equal "Acknowledge this alert: http://nagios.example.com/nagios/cgi-bin/cmd.cgi?cmd_typ=34&host=web.example.com&service=Disk%20Space<br>Alternatively, <b>reply</b> to this message with the word '<b><font color='green'>ack</font></b>' in the body to acknowledge the alert.<br>", @formatter.content[:html][:alert_ack_url]
|
122
|
+
assert_equal "Acknowledge this alert: http://nagios.example.com/nagios/cgi-bin/cmd.cgi?cmd_typ=34&host=web.example.com&service=Disk%20Space\nAlternatively, reply to this message with the word 'ack' in the body to acknowledge the alert.\n", @formatter.content[:text][:alert_ack_url]
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_clean_sandbox
|
126
|
+
@formatter.clean_sandbox
|
127
|
+
assert !File.directory?(@formatter.sandbox)
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
4
|
+
require 'nagios-herald'
|
5
|
+
require 'nagios-herald/config'
|
6
|
+
require 'nagios-herald/executor'
|
7
|
+
require 'nagios-herald/formatters/base'
|
8
|
+
|
9
|
+
# Test Formatter::Base.
|
10
|
+
class TestFormatterCheckCpuIdle < MiniTest::Unit::TestCase
|
11
|
+
|
12
|
+
# TODO: We need a similar set of tests for RECOVERY emails.
|
13
|
+
# Initial setup before we execute tests
|
14
|
+
def setup
|
15
|
+
@options = {}
|
16
|
+
@options[:message_type] = 'EMAIL'
|
17
|
+
@options[:nagios_url] = "http://nagios.example.com"
|
18
|
+
@options[:formatter_name] = 'check_cpu'
|
19
|
+
env_file = File.join(File.dirname(__FILE__), '..', 'env_files', 'check_cpu_idle.CRITICAL')
|
20
|
+
NagiosHerald::Executor.new.load_env_from_file(env_file) # load an env file for testing
|
21
|
+
NagiosHerald::Executor.new.load_formatters
|
22
|
+
NagiosHerald::Executor.new.load_messages
|
23
|
+
formatter_class = NagiosHerald::Formatter.formatters[@options[:formatter_name]]
|
24
|
+
@formatter = formatter_class.new(@options)
|
25
|
+
end
|
26
|
+
|
27
|
+
def teardown
|
28
|
+
# make certain we don't leave tons of empty temp dirs behind
|
29
|
+
@formatter.clean_sandbox
|
30
|
+
end
|
31
|
+
|
32
|
+
# Test that we have a new NagiosHerald::Formatter object.
|
33
|
+
def test_new_formatter
|
34
|
+
assert_instance_of NagiosHerald::Formatter::CheckCpu, @formatter
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_add_content_basic
|
38
|
+
@formatter.add_text('test_add_content', 'This is test text')
|
39
|
+
assert_equal 'This is test text', @formatter.content[:text][:test_add_content]
|
40
|
+
@formatter.add_html('test_add_content', '<b>This is test HTML</b>')
|
41
|
+
assert_equal '<b>This is test HTML</b>', @formatter.content[:html][:test_add_content]
|
42
|
+
@formatter.generate_subject
|
43
|
+
assert_equal "PROBLEM Service web.example.com/CPU is CRITICAL", @formatter.content[:subject]
|
44
|
+
attachment_name = "#{@formatter.sandbox}/cat.gif"
|
45
|
+
@formatter.add_attachment(attachment_name)
|
46
|
+
assert @formatter.content[:attachments].include?(attachment_name), "Failed to attach #{attachment_name} to content hash."
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_action_url
|
50
|
+
@formatter.action_url
|
51
|
+
assert_equal "<b>Action URL</b>: http://runbook.example.com/disk_space_alerts.html<br><br>", @formatter.content[:html][:action_url]
|
52
|
+
assert_equal "Action URL: http://runbook.example.com/disk_space_alerts.html\n\n", @formatter.content[:text][:action_url]
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_host_info
|
56
|
+
@formatter.host_info
|
57
|
+
assert_equal "<br><b>Host</b>: web.example.com <b>Service</b>: CPU<br/><br>", @formatter.content[:html][:host_info]
|
58
|
+
assert_equal "Host: web.example.com Service: CPU\n\n", @formatter.content[:text][:host_info]
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_state_info
|
62
|
+
@formatter.state_info
|
63
|
+
assert_equal "State is now: <b><font style='color:red'>CRITICAL</font></b> for <b>0d 0h 0m 14s</b> (was WARNING) after <b>3 / 3</b> checks<br/><br>", @formatter.content[:html][:state_info]
|
64
|
+
assert_equal "State is now: CRITICAL for 0d 0h 0m 14s (was WARNING) after 3 / 3 checks\n\n", @formatter.content[:text][:state_info]
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_notification_info
|
68
|
+
@formatter.notification_info
|
69
|
+
assert_equal "Notification sent at: Sat May 17 01:34:07 UTC 2014 (notification number 2)<br><br>", @formatter.content[:html][:notification_info]
|
70
|
+
assert_equal "Notification sent at: Sat May 17 01:34:07 UTC 2014 (notification number 2)\n\n", @formatter.content[:text][:notification_info]
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_additional_info
|
74
|
+
@formatter.additional_info
|
75
|
+
assert_equal "<b>Additional Info</b>:<br>CRITICAL CPU <b><font color='red'>idle</font></b> is < 100%: user=3.02% system=3.25% iowait=0.01% <b><font color='red'>idle=93.72%</font></b>", @formatter.content[:html][:additional_info]
|
76
|
+
assert_equal "Additional Info: CRITICAL CPU idle is < 100%: user=3.02% system=3.25% iowait=0.01% idle=93.72%", @formatter.content[:text][:additional_info]
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_additional_details
|
80
|
+
@formatter.additional_details
|
81
|
+
puts
|
82
|
+
assert_equal "<b>Additional Details</b>:<pre><br>TOP 5 PROCESSES BY CPU:<br> %CPU TIME USER PID COMMAND<br><font color='red'> 57.6 00:00:15 root 21751 /usr/bin/ruby /usr/bin/knife search node lastrun_status:success -i</font><br><font color='orange'> 4.0 00:00:00 larry 22001 ps -eo %cpu,cputime,user,pid,args --sort -%cpu</font><br><font color='orange'> 0.7 06:19:12 nobody 12161 /usr/sbin/gmond</font><br><font color='orange'> 0.6 1-02:11:15 root 1424 [kipmi0]</font><br><font color='orange'> 0.5 00:48:01 10231 15079 mosh-server new -s -c 8 -l LANG=en_US.UTF-8</font><br></pre><br>", @formatter.content[:html][:additional_details]
|
83
|
+
assert_equal "Additional Details:\n#TOP 5 PROCESSES BY CPU:\n %CPU TIME USER PID COMMAND\n 57.6 00:00:15 root 21751 /usr/bin/ruby /usr/bin/knife search node lastrun_status:success -i\n 4.0 00:00:00 larry 22001 ps -eo %cpu,cputime,user,pid,args --sort -%cpu\n 0.7 06:19:12 nobody 12161 /usr/sbin/gmond\n 0.6 1-02:11:15 root 1424 [kipmi0]\n 0.5 00:48:01 10231 15079 mosh-server new -s -c 8 -l LANG=en_US.UTF-8\n\n\n", @formatter.content[:text][:additional_details]
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_notes
|
87
|
+
@formatter.notes
|
88
|
+
# There are no notes in the example environment variables.
|
89
|
+
assert_equal "", @formatter.content[:html][:notes]
|
90
|
+
assert_equal "", @formatter.content[:text][:notes]
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_action_url
|
94
|
+
@formatter.action_url
|
95
|
+
assert_equal "", @formatter.content[:html][:action_url]
|
96
|
+
assert_equal "", @formatter.content[:text][:action_url]
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_short_state_detail
|
100
|
+
@formatter.short_state_detail
|
101
|
+
assert_equal "CRITICAL CPU idle is < 100%: user=3.02% system=3.25% iowait=0.01% idle=93.72%<br>", @formatter.content[:html][:short_state_detail]
|
102
|
+
assert_equal "CRITICAL CPU idle is < 100%: user=3.02% system=3.25% iowait=0.01% idle=93.72%\n", @formatter.content[:text][:short_state_detail]
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_recipients_email_link
|
106
|
+
@formatter.recipients_email_link
|
107
|
+
assert_equal "Sent to ops<br><br>", @formatter.content[:html][:recipients_email_link]
|
108
|
+
assert_equal "Sent to ops\n\n", @formatter.content[:text][:recipients_email_link]
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_ack_info
|
112
|
+
@formatter.ack_info
|
113
|
+
assert_equal "At Sat May 17 01:34:07 UTC 2014 acknowledged web.example.com/CPU.<br><br>Comment: ", @formatter.content[:html][:ack_info]
|
114
|
+
assert_equal "At Sat May 17 01:34:07 UTC 2014 acknowledged web.example.com/CPU.\n\nComment: ", @formatter.content[:text][:ack_info]
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_short_ack_info
|
118
|
+
@formatter.short_ack_info
|
119
|
+
assert_equal " ack'd CPU on web.example.com.<br>", @formatter.content[:html][:short_ack_info]
|
120
|
+
assert_equal " ack'd CPU on web.example.com.\n", @formatter.content[:text][:short_ack_info]
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_alert_ack_url
|
124
|
+
@formatter.alert_ack_url
|
125
|
+
assert_equal "Acknowledge this alert: http://nagios.example.com/nagios/cgi-bin/cmd.cgi?cmd_typ=34&host=web.example.com&service=CPU<br>Alternatively, <b>reply</b> to this message with the word '<b><font color='green'>ack</font></b>' in the body to acknowledge the alert.<br>", @formatter.content[:html][:alert_ack_url]
|
126
|
+
assert_equal "Acknowledge this alert: http://nagios.example.com/nagios/cgi-bin/cmd.cgi?cmd_typ=34&host=web.example.com&service=CPU\nAlternatively, reply to this message with the word 'ack' in the body to acknowledge the alert.\n", @formatter.content[:text][:alert_ack_url]
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_clean_sandbox
|
130
|
+
@formatter.clean_sandbox
|
131
|
+
assert !File.directory?(@formatter.sandbox)
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|