This file is indexed.

/usr/lib/nagios/plugins/check_smstools is in nagios-plugins-contrib 9.20140106.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/usr/bin/perl

#
# Retrieves the status of an SMS Modem via smstools3.
#

# Author: Patrick Schoenfeld <schoenfeld@debian.org>
# This file is licensed under the terms of the GPL v2 or later.
# See the file COPYING for details.

# Currently this plugin does not work with nagios embedded perl
# nagios: -epn

use strict;
use warnings;
use Nagios::Plugin;
use POSIX;

# Define regular expressions used to find the correct lines from
# the status file
my $signal_command = 'AT\+CSQ';
my $registration_status_command = 'AT\+CREG\?';
my $operator_command = 'AT\+COPS\?';

# Define a regular expression that is used to check against
# the answer of the modem to the AT+CREG? command in order
# to determine registration status of the modem
my $registration_status_expect = '.,1';

# Define the default path of the status file
my $status_file = '/var/log/smstools/smsd_stats/modem_status';

# Default Threshoulds
my $warning_lvl = 12;	# WARNING, if signal level < threshould
my $critical_lvl = 10;	# CRITICAL, if signal level < threshould
my $maxage = 60;	# CRIRTICAL, if status file is more then x seconds old

# Status variables
my $siglvl;
my $sigdbm;
my $operator;
my $expected_operator;
my $registration_status;
my $timestamp;
my $np;

sub init_plugin {
	$np = Nagios::Plugin->new(usage => "usage: %s");

	$np->add_arg(
		spec => 'warning|w=f',
		help => 'the signal level (as a positive float between 0..32) at which' .
			'to emit a WARNING state if the signal level is below this value'
	);

	$np->add_arg(
		spec => 'critical|c=f',
		help => 'the signal level (as a positive float between 0..32) at which to ' .
			'emit a CRITICAL state if the signal level is below this value'
	);

	$np->add_arg(
		spec => 'max-age=i',
		help => 'specify the maximum tolerated age of the status file in seconds'
	);

	$np->add_arg(
		spec => 'status-file=s',
		help => 'specifies the file which is checked for the status information'
	);

	$np->add_arg(
		spec => 'expected-operator=s',
		help => 'Specifies an operator that is expected. If the registered operator ' .
			'is not the same as specified here, the plugin will exit with a ' .
			'CRITICAL state'
	);

	$np->add_arg(
		spec => 'debug|d',
		help => 'Enable debug mode'
	);

	$np->getopts;

	if ($np->opts->warning) {
		$warning_lvl = $np->opts->warning;
	}

	if ($np->opts->critical) {
		$critical_lvl = $np->opts->critical;
	}

	if ($np->opts->get('status-file')) {
		$status_file = $np->opts->get('status-file');
	}

	if ($np->opts->get('max-age')) {
		$maxage = $np->opts->get('max-age');
	}

	if ($np->opts->get('expected-operator')) {
		$expected_operator = $np->opts->get('expected-operator');
	}
	if ($critical_lvl > $warning_lvl) {
		$np->nagios_die("Critical level ($critical_lvl) is higher then the warning level ($warning_lvl)");
	}

	# Test if status_file is readable	
	unless (-r $status_file)
	{
		$np->nagios_die("Unable to read modem status file");
	}
}

sub parse_logline {
	my $line = shift;
	my %result;

	# Use the line without the timestamp
	$line = substr($line, 22);
	$line =~ s/://g;

	# Split line into an array
	my @line = split(/\s/, $line);

	# Modem
	chomp $line[1];
	$result{'modem'} = $line[1];

	# Command
	$result{'cmd'} = $line[3];

	# Answer
	$result{'answer'} = $line[5];

	return %result;
}

sub process_statusfile {
	open(STATUS_FILE, "< $status_file") or $np->nagios_die("Unable to open modem status file");

	# Check status file freshness
	my $fileage = (stat(STATUS_FILE))[9];
	my $fileage_difference = time() - $fileage;

	if ($fileage_difference > $maxage) {
		$np->nagios_exit(CRITICAL, "Status file has not changed since $maxage seconds\n");
	}

	while(<STATUS_FILE>) {
		my %result = parse_logline($_);

		unless ($registration_status) {
			if ($result{'cmd'} =~ /$registration_status_command/) {
				$registration_status = $result{'answer'};
			}
		}

		unless ($siglvl) {
			if ($result{'cmd'} =~ /$signal_command/) {
				$siglvl = $result{'answer'};
				$siglvl =~ s/,/./g;
				$sigdbm = (2*$siglvl) - 113;
			}
		}

		unless ($operator) {
			if ($result{'cmd'} =~ /$operator_command/) {
				$operator = $result{'answer'};
				$operator =~ s/0,0,"//g;
			}
		}
		# No need to parse the rest of the file, if signal
		# and registration status are known
		if ($siglvl and $registration_status and $operator) {
			last;
		}
	}

	close(STATUS_FILE);
}

sub check_registration {
	unless ($registration_status) {
		$np->nagios_die("Unable to determine modem registration status.");
	}

	unless ($registration_status =~ /$registration_status_expect/) {
		$np->nagios_exit(CRITICAL, "Modem is not registered to a GSM network.");
	}
}

sub check_signal {
	unless ($siglvl) {
		$np->nagios_die("Unable to determine the modem signal strength.");
	}

	if (($siglvl < 0) or ($siglvl > 31)) {
		$np->nagios_die("Unable to determine the modem signal strength.");
	}

	# Add performance data information
	$np->add_perfdata(
		label => 'level',
		value => $siglvl
	);

	$np->add_perfdata(
		label => 'dBm',
		value => $sigdbm
	);

	if ($siglvl <= $critical_lvl) {
		$np->nagios_exit(CRITICAL, "Modem is registered ($operator), but signal quality ($siglvl) is below threshould.");
	}

	if ($siglvl <= $warning_lvl) {
		$np->nagios_exit(WARNING, "Modem is registered ($operator), but signal quality ($siglvl) is below threshould.");
	}

	# If we get here we can exit with OK
	$np->nagios_exit(OK, "Modem is registered ($operator). Signal quality is $siglvl / $sigdbm dBm.");
}

sub check_operator {
	unless ($operator) {
		$operator = "Unknown Operator";
	}

	if ($expected_operator) {
		if ($operator ne $expected_operator) {
			$np->nagios_exit(CRITICAL, "Modem is registered to $operator while $expected_operator is expected.");
		}
	}
}
init_plugin;
process_statusfile;
check_registration;
check_operator;
check_signal;