Skip to content

Instantly share code, notes, and snippets.

@niklasf
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niklasf/3e6704459fa5fd44a2aa to your computer and use it in GitHub Desktop.
Save niklasf/3e6704459fa5fd44a2aa to your computer and use it in GitHub Desktop.
Nagios plugin that checks the temperature of thermal_zone0
#!/usr/bin/perl
#
# Copyright (c) 2014 Niklas Fiekas <niklas.fiekas@tu-clausthal.de>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
use strict;
use Nagios::Plugin;
my $np = Nagios::Plugin->new(
usage => "Usage: %s [-w <warning>] [-c <critical>]",
version => '0.1',
url => 'https://gist.github.com/niklasf/3e6704459fa5fd44a2aa',
blurb => 'Checks the temperature of thermal_zone0.',
);
$np->add_arg(
spec => 'warning|w=s',
help => '-w, --warning=RANGE'
);
$np->add_arg(
spec => 'critical|c=s',
help => '-c, --critical=RANGE'
);
$np->getopts;
unless (-e '/sys/class/thermal/thermal_zone0/temp') {
$np->nagios_die('/sys/class/thermal/thermal_zone0/temp not found');
}
my $max_temp;
my $max_zone;
my $max_code = OK;
for (my $zone = 0; -e "/sys/class/thermal/thermal_zone$zone/temp"; $zone++) {
open my $file, '<', "/sys/class/thermal/thermal_zone$zone/temp" or
$np->nagios_die("Could not open /sys/class/thermal/thermal_zone$zone/temp");
my $temp = int(<$file>) / 1000.0;
close $file;
if ($zone == 0 || $temp > $max_temp) {
$max_temp = $temp;
$max_zone = $zone;
}
$np->add_perfdata(
label => "thermal_zone$zone",
value => $temp,
warning => $np->opts->warning,
critical => $np->opts->critical,
);
my $code = $np->check_threshold(
check => $temp,
warning => $np->opts->warning,
critical => $np->opts->critical,
);
$max_code = $max_code > $code ? $max_code : $code;
}
$np->nagios_exit($max_code, "Maximum temperature is $max_temp C in thermal_zone$max_zone");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment