-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_sap_icm.pl
174 lines (126 loc) · 3.35 KB
/
check_sap_icm.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/perl
## Copyright (c) 20014 Kai Knoepfel
##
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License
## as published by the Free Software Foundation; either version 2
## of the License, or (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
use LWP::UserAgent;
use Getopt::Long;
#
# Dont change anything below these lines ...
#
GetOptions(
"v" => \$ver,
"version" => \$ver,
"h" => \$help,
"help" => \$help,
"host=s" => \$host, # monitored-system
"port=i" => \$port, # icm-port
"debug" => \$debug, # debugging
"t=i" => \$timec, # timeout of the check
"time=i" => \$timec, # timeout of the check
);
version();
help();
timeout();
# timeout routine
$SIG{ALRM} = \&plugin_timeout;
eval {
alarm ($timeout);
};
if ( $host eq undef || $port eq undef || $timec eq undef)
{
print "Please use -h or -help to use the script with correct syntax!!\n";
}
else
{
my $ua = new LWP::UserAgent;
$ua->agent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');
my $system_date = `date '+%Y-%m-%d'`;
my $response = $ua->post("http://$host:$port/sap/public/ping");
my $content = $response->content;
if ( $debug == 1 )
{
print "$content\n";
}
my $login_ok = grep /erfolgreich|available/, $content;
my $login_maint = grep /Maintenance/, $content;
my $login_error = grep /Can't connect/, $content;
if ( $login_ok == "1" )
{
print "OK - ICM on $host available!\n";
exit 0;
}
elsif ( $login_maint == "1" )
{
print "WARNING - ICM on $host are in Maintenance-Mode!\n";
exit 1;
}
elsif ( $login_error == "1" )
{
print "CRITICAL - ICM on $host not available!\n";
exit 2;
}
else
{
print "UNKNOWN - An error occurred!\n";
print "$content\n";
exit 3;
}
}
sub help{
if ( $help == "1" )
{
print "\n";
print "Usage:\n";
print " check_sap_icm.pl -host <HOSTNAME> -port <HTTP-PORT>\n";
print "\n";
print "Optionen:\n";
print "\n";
print " -host: HOSTNAME\n";
print "\n";
print " -port: ICM-Port\n";
print "\n";
print " -debug -> For debug output.\n";
print "\n";
print " -t -> For debug output.\n";
print "\n";
print "Help:\n";
print "\n";
print " To use this plugin you must activate the sicf-service /sap/public/ping\n";
print " You need the following perl-modules: LWP::UserAgent, Getopt::Long\n";
print "\n";
}
}
sub version{
if ( $ver == "1" )
{
print "\n";
print "Version: \n";
print "0.1 -> add Getopt::Long\n";
print "\n";
print "For changes, ideas or bugs please contact kutte013\@gmail.com\n";
print "\n";
exit 0;
}
}
sub timeout{
if ( $timec != $conf{timedef} )
{
$timeout = $timec;
}
else
{
$timeout = $conf{timedef};
}
}