Home Directory

Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

Directory Tree

Directory

IamiceFi

Reviews(1)
We made a change to checkservice in to the perl script so we can exclude services.

#-------------------------------------------------------------------------
sub checkservice {
# ------------------------ checking all services
my $where_bit='';
my $auto_mode='';
my $invert_mode='';

if (lc($the_arguments{'_arg1'}) eq 'auto') {
# for this query we need to look for all automatic services
# check that all auto services are
# STARTED=True, STATE=Running and STATUS=OK
# we do a query that actually always should return data so that we know that the query works
# we could do a select just listing the bad ones, but it returns nothing if good. hard to tell if it really worked ok.
$where_bit="where StartMode=\"auto\"";
$auto_mode=1;
} elsif (lc($the_arguments{'_arg1'}) eq 'invert') {
$where_bit="where StartMode=\"auto\"";

$auto_mode=1;
if ($the_arguments{'_arg2'} ne '') {
$invert_mode=1;
}

} else {
# for this query we have been passed a regex and must look for that
# so the WMI query should return all services and then we will apply the regex
# this is the default
}

# wmic returns something like:
# CLASS: Win32_Service
# DisplayName|Name|Started|StartMode|State|Status
# Telnet|TlntSvr|False|Auto|Stopped|OK
# Security Center|wscsvc|True|Auto|Running|OK

my @collected_data;
my $data_errors=get_multiple_wmi_samples(1,
"select displayname, Started, StartMode, State, Status FROM Win32_Service $where_bit",
'','',\@collected_data,\$the_arguments{'_delay'},undef,0);

check_for_data_errors($data_errors);

# at this point we can assume that we have all the data we need stored in @collected_data
my $result_text='';
# now loop through the results, showing the ones requested
my $num_ok=0;
my $num_bad=0;
# so we want to loop through all the rows in the first query result $collected_data[0]
foreach my $row (@{$collected_data[0]}) {
$debug && print "Service Info: " . Dumper($row);
# in the middle of the WMI output there are lines like:
# CLASS: Win32_Service
# CLASS: Win32_TerminalService
# which means DisplayName and Name might not be set so we need to test for this to stop
# "Use of uninitialized value in pattern match" errors
if ($$row{'DisplayName'} && $$row{'Name'}) {
if ( $auto_mode ||
( !$auto_mode && ($$row{'DisplayName'}=~/$the_arguments{'_arg1'}/i || $$row{'Name'}=~/$the_arguments{'_arg1'}/i) )
) {
if ($$row{'Started'} eq 'True' && $$row{'State'} eq 'Running' && $$row{'Status'} eq 'OK') {
$num_ok++;
if (!$auto_mode) {
# if we have using the regex mode then list out the services we find
$result_text.="'$$row{'DisplayName'}' ($$row{'Name'}) is $$row{'State'}, ";
}
} else {
if (!$invert_mode) {
$num_bad++;
$result_text.="'$$row{'DisplayName'}' ($$row{'Name'}) is $$row{'State'}, ";
} else {
if ($$row{'DisplayName'}!~/$the_arguments{'_arg2'}/i && $$row{'Name'}!~/$the_arguments{'_arg2'}/i) {
$num_bad++;
$result_text.="'$$row{'DisplayName'}' ($$row{'Name'}) is $$row{'State'}, ";
}
}
}
}
}
}

$result_text=~s/, $/./;

# load some values to check warn/crit against
$collected_data[0][0]{'_NumGood'}=$num_ok;
$collected_data[0][0]{'_NumBad'}=$num_bad;
$collected_data[0][0]{'_Total'}=$num_ok+$num_bad;
$collected_data[0][0]{'_ServiceList'}=$result_text;

my $test_result=test_limits($opt_warn,$opt_critical,$collected_data[0][0],\%warn_perf_specs_parsed,\%critical_perf_specs_parsed,\@warn_spec_result_list,\@critical_spec_result_list);

my ($this_display_info,$this_performance_data,$this_combined_data)=create_display_and_performance_data($collected_data[0][0],$display_fields{$opt_mode},$performance_data_fields{$opt_mode},\%warn_perf_specs_
print $this_combined_data;

exit $test_result;

---------

So you'll have to give -a invert -o $ARG2 parameter where $ARG2 can be "service1|service2|service3" etc. The listed services will be excluded from the check.