From: Peter Palfrader Date: Mon, 20 Mar 2017 08:29:23 +0000 (+0100) Subject: Move dsa-check-memory to checks/ X-Git-Url: https://git.adam-barratt.org.uk/?p=mirror%2Fdsa-nagios.git;a=commitdiff_plain;h=f1979c65de912f98b484c096e19e461ba57b8f84 Move dsa-check-memory to checks/ --- diff --git a/dsa-nagios-checks/checks/dsa-check-memory b/dsa-nagios-checks/checks/dsa-check-memory new file mode 100755 index 0000000..e01f7d8 --- /dev/null +++ b/dsa-nagios-checks/checks/dsa-check-memory @@ -0,0 +1,92 @@ +#!/usr/bin/python + +# Copyright 2013 Stephen Gran +# +# 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. + +from optparse import OptionParser +import sys + +parser = OptionParser(version='0.1') +parser.add_option("-w", "--warning", dest="warn", default=False, help="warning level") +parser.add_option("-c", "--critical", dest="crit", default=False, help="critical level") +parser.add_option("-m", "--mode", dest="mode", default='mb', help="Check mode (mb or pct)") + +exit_codes = { + 'OK': 0, + 'WARNING': 1, + 'CRITICAL': 2, + 'UNKNOWN': 3 +} + +(options, args) = parser.parse_args() + +if options.mode == 'mb': + options.warn = options.warn or 500 + options.crit = options.crit or 100 +elif options.mode == 'pct': + options.warn = options.warn or 10 + options.crit = options.crit or 5 +else: + print "What mode is %s?" % options.mode + sys.exit(1) + +options.warn = int(options.warn) +options.crit = int(options.crit) + +with open('/proc/meminfo', 'r') as fd: + data = fd.readlines() + +memset = {} +interesting_keys = ['MemTotal', 'MemFree', 'Buffers', 'Cached', 'SwapTotal', 'SwapFree'] + +for line in data: + temp = line.split() + temp[0] = temp[0][:-1] + if temp[0] in interesting_keys: + memset[temp[0]] = int(temp[1]) + +total_vm = memset['MemTotal'] + memset['SwapTotal'] +avail_vm = memset['MemFree'] + memset['Buffers'] +\ + memset['Cached'] + memset['SwapFree'] + +free_pct = int((avail_vm * 100)/total_vm) +used_mem = int(total_vm - avail_vm) + +if options.mode == 'pct': + if free_pct < options.crit: + print "CRITICAL: Free VM: %d%%" % free_pct + sys.exit(exit_codes['CRITICAL']) + elif free_pct < options.warn: + print "WARNING: Free VM: %d%%" % free_pct + sys.exit(exit_codes['WARNING']) + else: + print "OK: Free VM: %d%%" % free_pct + sys.exit(exit_codes['OK']) +else: + if avail_vm < options.crit: + print "CRITICAL: Free VM: %d" % avail_vm + sys.exit(exit_codes['CRITICAL']) + elif avail_vm < options.warn: + print "WARNING: Free VM: %d" % avail_vm + sys.exit(exit_codes['WARNING']) + else: + print "OK: Free VM: %d" % avail_vm + sys.exit(exit_codes['OK']) diff --git a/dsa-nagios-checks/debian/changelog b/dsa-nagios-checks/debian/changelog index dc80b42..d04c057 100644 --- a/dsa-nagios-checks/debian/changelog +++ b/dsa-nagios-checks/debian/changelog @@ -8,6 +8,8 @@ dsa-nagios-checks (110) UNRELEASED; urgency=medium * dsa-check-running-kernel: meta package version check, also work on 4.x kernels and later. * dsa-check_puppet_agent: add from Alexander Swen's github. + * dsa-check-memory: move from / to /checks in source (so now it should get + installed.) -- Peter Palfrader Mon, 23 Jan 2017 14:14:06 +0100 diff --git a/dsa-nagios-checks/dsa-check-memory b/dsa-nagios-checks/dsa-check-memory deleted file mode 100755 index e01f7d8..0000000 --- a/dsa-nagios-checks/dsa-check-memory +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/python - -# Copyright 2013 Stephen Gran -# -# 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. - -from optparse import OptionParser -import sys - -parser = OptionParser(version='0.1') -parser.add_option("-w", "--warning", dest="warn", default=False, help="warning level") -parser.add_option("-c", "--critical", dest="crit", default=False, help="critical level") -parser.add_option("-m", "--mode", dest="mode", default='mb', help="Check mode (mb or pct)") - -exit_codes = { - 'OK': 0, - 'WARNING': 1, - 'CRITICAL': 2, - 'UNKNOWN': 3 -} - -(options, args) = parser.parse_args() - -if options.mode == 'mb': - options.warn = options.warn or 500 - options.crit = options.crit or 100 -elif options.mode == 'pct': - options.warn = options.warn or 10 - options.crit = options.crit or 5 -else: - print "What mode is %s?" % options.mode - sys.exit(1) - -options.warn = int(options.warn) -options.crit = int(options.crit) - -with open('/proc/meminfo', 'r') as fd: - data = fd.readlines() - -memset = {} -interesting_keys = ['MemTotal', 'MemFree', 'Buffers', 'Cached', 'SwapTotal', 'SwapFree'] - -for line in data: - temp = line.split() - temp[0] = temp[0][:-1] - if temp[0] in interesting_keys: - memset[temp[0]] = int(temp[1]) - -total_vm = memset['MemTotal'] + memset['SwapTotal'] -avail_vm = memset['MemFree'] + memset['Buffers'] +\ - memset['Cached'] + memset['SwapFree'] - -free_pct = int((avail_vm * 100)/total_vm) -used_mem = int(total_vm - avail_vm) - -if options.mode == 'pct': - if free_pct < options.crit: - print "CRITICAL: Free VM: %d%%" % free_pct - sys.exit(exit_codes['CRITICAL']) - elif free_pct < options.warn: - print "WARNING: Free VM: %d%%" % free_pct - sys.exit(exit_codes['WARNING']) - else: - print "OK: Free VM: %d%%" % free_pct - sys.exit(exit_codes['OK']) -else: - if avail_vm < options.crit: - print "CRITICAL: Free VM: %d" % avail_vm - sys.exit(exit_codes['CRITICAL']) - elif avail_vm < options.warn: - print "WARNING: Free VM: %d" % avail_vm - sys.exit(exit_codes['WARNING']) - else: - print "OK: Free VM: %d" % avail_vm - sys.exit(exit_codes['OK'])