forked from zwindler/check_skel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_skel.pl
109 lines (92 loc) · 2.53 KB
/
check_skel.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/perl
############################################################################
#Skeleton of nagios-like plugin using Perl
################################################################################
### Prerequisites ##############################################################
### Program main part###########################################################
#Nagios constants
my %ERRORS = ('OK', '0',
'WARNING', '1',
'CRITICAL', '2',
'UNKNOWN', '3');
#Initialisation
BEGIN { $ENV{PATH} = '/bin:/usr/bin:/usr/local/bin:/usr/sbin' }
my $ignore_error_output = "2>/dev/null";
my $os = os_uname();
#Getting arguments
my $warn = shift || 100*1024*1024;
my $critical = shift || 200*1024*1024;
#Calling subroutines for real work
my @collected_data = collect_data();
process_data(@collected_data);
#The process should have ended at "print_nagios_output". This is wrong
print "UNKNOWN: There is a problem with the plugin. Exiting.\n";
exit $ERRORS{"UNKNOWN"};
### Subroutines ################################################################
#Usage
sub usage()
{
print "\ncheck_skel.pl - v 1.0\n\n";
print "usage:\n";
exit $exit_codes{'UNKNOWN'};
}
#Useful function for OS dependant data collection
sub os_uname
{
my $uname = ( -e '/usr/bin/uname' ) ? '/usr/bin/uname' : '/bin/uname';
my $os = (`$uname 2>/dev/null`);
chomp $os;
return $os ? $os : undef;
}
#Collect data from monitored system
sub collect_data
{
my @collected_data;
if ($os eq "HP-UX")
{
#HP-UX specific code
}
elsif ($os eq "Linux")
{
#Linux specific code
}
else
{
#Unsupported or unrecognised OS
print "CRITICAL : OS $os not yet supported or not recognised";
exit $ERRORS{"CRITICAL"};
}
#Use this in case of unknown error in routine (e.g. command not returning expected output)
#print "UNKNOWN : some generic error message?\n";
#exit $ERRORS{"UNKNOW"};
return @collected_data;
}
#Process the collected data, return state and additional useful information
sub process_data
{
my $state;
my @collected_data = @_;
my $output;
my $perfdata;
my $print_answer;
if ($state eq "OK")
{
$output = "OK: some message explaining everything is OK with your own variables";
}
elsif ($state eq "WARNING")
{
$output = "WARNING: some warning message with your own variables";
}
else
{
$output = "CRITICAL: some critical message with your own variables";
}
#Add perfdata if it exists
if ($perfdata)
{
$print_answer .= "| $perfdata";
}
$print_answer .= "\n";
print $print_answer;
exit $ERRORS{$state};
}