Пример #1
0
    def setUp(self):
        """
        Reset argv and initialize a plugin for tests.

        """
        sys.argv = ['test_script']
        self.plugin = Plugin("This is just a test plugin.", "1.2.3")
Пример #2
0
#!/usr/bin/python
import collectd
import string
import sys

from NagAconda import Plugin

MyPlugin = Plugin("Plugin to check memory usage from collectd", "1.0")
MyPlugin.add_option('H', 'host', 'host to check.',   required=True)
MyPlugin.add_option('S','socket','Socket to connect to. (default=/var/run/collectd-unixsock)',required=False,default='/var/run/collectd-unixsock')

MyPlugin.enable_status('warning')
MyPlugin.enable_status('critical')
MyPlugin.start()


formula = "(#"+MyPlugin.options.host+"/memory/memory-free 0# + #"+MyPlugin.options.host+"/memory/memory-cached 0# + #"+MyPlugin.options.host+"/memory/memory-buffered 0# ) / ( #"+MyPlugin.options.host+"/memory/memory-free 0# + #t430s-fpg/memory/memory-cached 0# + #"+MyPlugin.options.host+"/memory/memory-buffered 0# + #"+MyPlugin.options.host+"/memory/memory-used 0#)*100"

c = collectd.Collect(MyPlugin.options.socket)
val=c.calculate(formula)


MyPlugin.set_value('mem_free', val, scale='%')

MyPlugin.finish()

#! /usr/bin/python

"""
check_celery.py
~~~~~~~~~

This is a monitoring plugin for Nagios NRPE. If required, ensure a copy of this is 
placed in the following directory on the host machine: /usr/local/nagios/libexec/
"""
import sys
import requests
import simplejson as json
from NagAconda import Plugin

check_api = Plugin("Used to determine the status of a Celery worker.", "1.0")

check_api.add_option("p", "port", "Port of the Celery host machine serving the Celerymon API. (default: 8989)", default=8989)
check_api.add_option("h", "host", "Host of the Celery worker instance. (default: http://localhost)", default="http://localhost")
check_api.add_option("a", "action", "The status check to perform. (nodeup, health)", default="health")
check_api.add_option("n", "node", "Check if a specified node is up. Used with `nodeup` action. (default: celery.ubuntu)", default="celery.ubuntu")
check_api.add_option("l", "limit", "Number of tasks in the past to check. (default: 100)", default=100)

check_api.enable_status("warning")
check_api.enable_status("critical")

check_api.start()

if check_api.options.action not in ("nodeup", "health"):
    check_api.unknown_error("unknown action specified %s." % check_api.options.action)

response = requests.get("%s:%d/api/worker/" % (check_api.options.host, int(check_api.options.port)))
Пример #4
0
#! /usr/bin/python
"""
check_celery.py
~~~~~~~~~

This is a monitoring plugin for Nagios NRPE. If required, ensure a copy of this is 
placed in the following directory on the host machine: /usr/local/nagios/libexec/
"""
import sys
import requests
import simplejson as json
from NagAconda import Plugin

check_api = Plugin("Used to determine the status of a Celery worker.", "1.0")

check_api.add_option(
    "p",
    "port",
    "Port of the Celery host machine serving the flower API. (default: 5555)",
    default=5555)
check_api.add_option(
    "h",
    "host",
    "Host of the Celery worker instance. (default: http://localhost)",
    default="http://localhost")
check_api.add_option("a",
                     "action",
                     "The status check to perform. (nodeup, health)",
                     default="health")
check_api.add_option(
    "n",
Пример #5
0
                    'Error while removing cache lock at %s: %s' %
                    (self.cache_lock_path, e))


if __name__ == '__main__':

    try:
        from NagAconda import Plugin
    except ImportError, e:
        print(
            '%s (Hint: "pip install NagAconda" or "easy_install NagAconda")' %
            e)
        sys.exit(2)

    # Initialize plugin
    plugin = Plugin(__description__, __version__)
    cache_path = os.path.join(os.path.expanduser('~'),
                              '.check_ganglia_metric.cache')
    plugin.add_option('d',
                      'gmetad_host',
                      'Ganglia meta daemon host (default: localhost)',
                      default='localhost')
    plugin.add_option('p',
                      'gmetad_port',
                      'Ganglia meta daemon port (default: 8651)',
                      default=8651)
    plugin.add_option(
        't',
        'gmetad_timeout',
        'Ganglia meta daemon connection/read timeout in seconds (default: 2)',
        default=2)
#!/usr/bin/python
import collectd
import string
import sys

from NagAconda import Plugin

MyPlugin = Plugin("Plugin to check swap usage from collectd", "1.0")
MyPlugin.add_option('H', 'host', 'host to check.',   required=True)
MyPlugin.add_option('S','socket','Socket to connect to. (default=/var/run/collectd-unixsock)',required=False,default='/var/run/collectd-unixsock')
MyPlugin.add_option('I','interfaces','interfaces to check (default=all)',required=False,default='all')
MyPlugin.add_option('v','version','CollectD version default=5.x',required=False,default=5)

MyPlugin.enable_status('warning')
MyPlugin.enable_status('critical')
MyPlugin.start()

c = collectd.Collect(MyPlugin.options.socket)


interfaces=[]
if MyPlugin.options.interfaces == 'all':
		interfaces=c.interfaces(MyPlugin.options.host)
else:
	interfaces=MyPlugin.options.interfaces.split(',')

for interface in interfaces:
	if MyPlugin.options.version == '4':
		formula="#"+MyPlugin.options.host+"/interface/if_errors-"+interface+" 0#" 
		err_rx=c.calculate(formula)
		formula="#"+MyPlugin.options.host+"/interface/if_errors-"+interface+" 1#" 
Пример #7
0
        except StandardError, e:
            if os.path.exists(self.cache_lock_path):
                raise self.CacheUnlockError('Error while removing cache lock at %s: %s' %
                                           (self.cache_lock_path, e))


if __name__ == '__main__':

    try:
        from NagAconda import Plugin
    except ImportError, e:
        print('%s (Hint: "pip install NagAconda" or "easy_install NagAconda")' % e)
        sys.exit(2)

    # Initialize plugin
    plugin = Plugin(__description__, __version__)
    cache_path = os.path.join(os.path.expanduser('~'), '.check_ganglia_metric.cache')
    plugin.add_option('d', 'gmetad_host',
                      'Ganglia meta daemon host (default: localhost)',
                      default='localhost')
    plugin.add_option('p', 'gmetad_port',
                      'Ganglia meta daemon port (default: 8651)',
                      default=8651)
    plugin.add_option('t', 'gmetad_timeout',
                      'Ganglia meta daemon connection/read timeout in seconds (default: 2)',
                      default=2)
    plugin.add_option('f', 'cache_path',
                      'Cache path (default: %s)' % cache_path,
                      default=cache_path)
    plugin.add_option('l', 'cache_ttl',
                      'Cache TTL in seconds (default: 60)',
Пример #8
0
#!/usr/bin/python
# Von https://pythonhosted.org/NagAconda/plugin.html
from NagAconda import Plugin
import os
import subprocess
from pyparsing import *

btrfs_check = Plugin("Plugin to show disk usage of btrfs.", "0.1")
btrfs_check.add_option('m', 'mountpoint', 'mountpoint for btrfs',
    required=True)

btrfs_check.enable_status('warning')
btrfs_check.enable_status('critical')
btrfs_check.start()

btrfs_output = subprocess.check_output(["btrfs", "fi", "df", btrfs_check.options.mountpoint])

# DEBUG:
# print btrfs_output

# PyParsing definitions
#
# Output is something like:
# Data, RAID1: total=222.72GB, used=197.44GB
# System, RAID1: total=64.00MB, used=40.00KB
# System: total=4.00MB, used=0.00
# Metadata, RAID1: total=10.00GB, used=5.40GB

# Parse Byte values with units
byteDefs=["B", "KB", "MB", "GB", "TB", "PB", "EB"]
byteDef = oneOf(byteDefs)
Пример #9
0
            return (None)

        if 'values' in data:
            # Replace Nones with 0
            # Fixme: better to remove None values?
            vals = [x if x != None else 0 for x in data['values']]
            if debug: print 'DEBUG VALUES:',vals
            # return an average
            return (float(sum(vals))/float(len(vals)))
        else:
            return (None)
    else:
        # non 200 return code
        return (None)

g = Plugin("Graphite Nagios Plugin.", "0.9")

# FIXME: http vs https support, user auth?
g.add_option('t', 'target', 'Graphite Target', required=True)
g.add_option('h', 'host',   'Graphite Host', required=True)
g.add_option('w', 'window', 'Time Window', default='-5minutes')
g.add_option('u', 'units',  'Metric units', default='percent')

g.enable_status('critical')
g.enable_status('warning')

g.start()

# Bounds checking on crit and warn
if g.options.raw_critical < g.options.raw_warning:
    g.unknown_error("ERROR: Critical level (%s) is set LOWER than Warning level (%s)" % (
Пример #10
0
#!/usr/bin/python
import collectd
import string
import sys

from NagAconda import Plugin

MyPlugin = Plugin("Plugin to check partition usage from collectd", "1.0")
MyPlugin.add_option('H', 'host', 'host to check.',   required=True)
MyPlugin.add_option('S','socket','Socket to connect to. (default=/var/run/collectd-unixsock)',required=False,default='/var/run/collectd-unixsock')
MyPlugin.add_option('M','mounts','Mount-points to check (default=all)',required=False,default='all')
MyPlugin.add_option('v','version','CollectD version default=5.x',required=False,default=5)

MyPlugin.enable_status('warning')
MyPlugin.enable_status('critical')
MyPlugin.start()

c = collectd.Collect(MyPlugin.options.socket)


mounts=[]
if MyPlugin.options.mounts == 'all':
		mounts=c.mounts(MyPlugin.options.host)
else:
	mounts=MyPlugin.options.mounts.split(',')
	
for mount in mounts:
	mount=mount.replace('/','_').lstrip('/_')
	if mount == '':
		mount ="root"
	if MyPlugin.options.version == '4':
Пример #11
0
# 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.
"""
import math
import urllib2

from NagAconda import Plugin

graphite = Plugin("Plugin to retrieve data from graphite", "1.0")
graphite.add_option("u", "url", "URL to query for data", required=False)
graphite.add_option("m", "minute", "period of data to get", required=False)
graphite.add_option("-hM", "hostMafia", "host of Mafia server", required=False)
graphite.add_option("-kM", "keyMafia", "key string", required=False)

graphite.enable_status("warning")
graphite.enable_status("critical")
graphite.start()

url = graphite.options.url
if not url:
    url = ''.join([
        'http://localhost/render?format=raw',
        '&from=-', graphite.options.minute, 'minutes',
        '&target=servers.', graphite.options.hostMafia.replace('.', '_'),