-
Notifications
You must be signed in to change notification settings - Fork 1
/
nagios-growl.pl
89 lines (74 loc) · 1.65 KB
/
nagios-growl.pl
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
#!/usr/bin/perl -w
#
# Created by Mathieu Gagne 2009
# Updated by Guillaume Bisch, 2012
#
use strict;
use warnings;
use Growl::GNTP;
use Getopt::Long qw(:config no_ignore_case bundling);
# Default values
my $application = 'Nagios';
my $title = 'Alert';
my $message = '';
my $priority = 2;
my $sticky = 0;
my $destination = 'localhost';
my $password = '';
my $help = 0;
my $pod2usage = sub {
# Load Pod::Usage only if needed.
require "Pod/Usage.pm";
import Pod::Usage;
pod2usage(@_);
};
# Declare and retreive options
GetOptions(
'h|help' => \$help,
'a|application=s' => \$application,
't|title=s' => \$title,
'm|message=s' => \$message,
'P|priority=i' => \$priority,
's|sticky' => \$sticky,
'H|host=s' => \$destination,
'p|password=s' => \$password,
) or $pod2usage->(1);
# Print help
$pod2usage->(1) if $help;
# Validate options
if ( $application eq '' ) {
die "Error: Missing mandatory option: application\n";
}
if ( $title eq '' ) {
die "Error: Missing mandatory option: title\n";
}
if ( $message eq '' ) {
die "Error: Missing mandatory option: message\n";
}
if ( $priority eq '' ) {
die "Error: Missing mandatory option: priority\n";
}
if ( $password eq '' ) {
die "Error: Missing mandatory option: password\n";
}
#
# Main program
#
my $growl = Growl::GNTP->new(
AppName => $application,
PeerHost => $destination,
Password => $password
);
# Register the application
$growl->register([
{ Name => $application, },
]);
# Send the notification
$growl->notify(
Event => "Nagios",
Title => $title,
Message => $message,
Icon => "",
Priority => $priority,
Sticky => $sticky
);