forked from ripienaar/angelia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
angelia-nagios-send.rb
executable file
·61 lines (51 loc) · 1.36 KB
/
angelia-nagios-send.rb
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
#!/usr/bin/ruby
require 'angelia'
require 'getoptlong'
conffile = nil
recipient = nil
subject = ""
message = ""
mode = nil
backend = "nagios"
opts = GetoptLong.new(
[ '--config', '-c', GetoptLong::REQUIRED_ARGUMENT],
[ '--recipient', '-r', GetoptLong::REQUIRED_ARGUMENT],
[ '--subject', '-s', GetoptLong::REQUIRED_ARGUMENT],
[ '--icinga', GetoptLong::NO_ARGUMENT],
[ '--host-notify', GetoptLong::NO_ARGUMENT],
[ '--service-notify', GetoptLong::NO_ARGUMENT],
[ '--message', '-m', GetoptLong::REQUIRED_ARGUMENT]
)
opts.each do |opt, arg|
case opt
when '--config'
conffile = arg
when '--recipient'
recipient = arg
when '--subject'
subject = arg
when '--icinga'
backend = 'icinga'
when '--host-notify'
mode = 'host'
when '--service-notify'
mode = 'service'
when '--message'
message = arg.gsub "\\n", "\n"
end
end
unless File.exists? conffile
raise "Can't find config file #{conffile}"
end
unless mode
raise "Must supply either --host-notify or --service-notify"
end
begin
Angelia::Config.new(conffile, false)
Angelia::Spool.createmsg Angelia::Message.new(recipient, message, subject, "#{backend}-#{mode}")
rescue Angelia::CorruptMessage => e
Angelia::Util.fatal("Could not create message: #{e}")
rescue Exception => e
$stderr.puts("Fatal error, message not sent: #{e}")
raise
end