Example #1
0
 def setUp(self):
     self.argv_store = sys.argv
     from pynag.Plugins import PluginHelper
     self.my_plugin = PluginHelper()
     self.my_plugin.parser.add_option('-F',
                                      dest='fakedata',
                                      help='fake data to test thresholds')
Example #2
0
    def check_metric(self):
        """Check if the metric value is within the threshold range, and exits with status code,
        message and perfdata.
        """

        # Get values
        metric_values = self._get_metric_values()
        unit = self._AZURE_METRICS_UNIT_SYMBOLS.get(
            self._metric_properties['unit'])
        if unit is None:
            unit = ''

        # Test if value to display
        if metric_values is None:
            message = 'No value available for metric {}'.format(self['metric'])
            if self['dimension'] is not None:
                message += ' and dimension {}'.format(self['dimension'])
            self.nagios_exit(Plugins.UNKNOWN, message)

        # PluginHelper of pynag import
        # https://pynag.readthedocs.io/en/latest/pynag.Plugins.html?highlight=check_threshold#pynag.Plugins.PluginHelper
        p = PluginHelper()

        # For each value, declare metric with according thresholds
        for metric_idx in metric_values:
            p.add_metric(label=metric_idx,
                         value=metric_values[metric_idx],
                         uom=unit,
                         warn=self['warning'],
                         crit=self['critical'])

        # Test all metrics according to there thresholds
        p.check_all_metrics()

        # Add global summary for output
        p.add_summary(self._metric_properties['name']['localizedValue'])

        # Exit and display plugin output
        p.exit()
Example #3
0
def main():
    p = PluginHelper()

    # Warn on inactive
    level = 2

    service_status = get_service_status(sys.argv[1])

    if loaded(service_status)[0] is False:
        p.exit(3,
               "%s - %s" % (service_status['name'], loaded(service_status)[1]),
               "\n" + service_status['unparsed'])

    active = service_status['headers']['Active'][0]
    if active.startswith("inactive") or active.startswith('failed'):
        p.add_status(level)
    elif active.startswith("active"):
        p.add_status(0)
    else:
        p.add_status(3)

    p.add_summary("%s - %s" % (service_status['name'], active))
    p.add_long_output("\n" + service_status['unparsed'])
    p.exit()
Example #4
0
#
# Example usage health:
# ./check_springboot_actuator.py -U "http://localhost:14041/testservice/v1/actuator"
#
# Example usage metrics:
# ./check_springboot_actuator.py -U "http://localhost:14041/testservice/v1/actuator" --th "metric=testservice.files.in.failure.value,ok=0..0,warning=1..20,critical=20..inf" -m testservice.files.in.failure

from __future__ import print_function

import logging

from pynag.Plugins import PluginHelper, ok, critical, unknown
from requests import get
from requests.exceptions import ConnectionError

helper = PluginHelper()

helper.parser.add_option(
    '-U', '--url',
    help='Base URL of Spring Boot Application (default: %default)',
    dest='url', default='http://localhost:8080')
helper.parser.add_option(
    '-N', '--no-check-certificate',
    help="don't verify certificate", dest='verify',
    action='store_false', default=True)
helper.parser.add_option(
    '-t', '--trust-store',
    help='trust store (PEM format) to use for TLS certificate validation',
    dest='truststore')
helper.parser.add_option(
    '-m', '--metrics',
Example #5
0
#!/usr/bin/env python

import requests
import string
import random
import sys
reload(sys)
sys.setdefaultencoding('utf-8')

from BeautifulSoup import BeautifulSoup
from pynag.Plugins import PluginHelper, ok, warning, critical, unknown

p = PluginHelper()

chars = string.letters + string.digits
randomstring = ''.join([random.choice(chars)
                        for i in xrange(4)])  # avoid cache
default_url = 'http://landspitali.is'
p.parser.add_option('--url', dest='url', default=default_url)
p.parse_arguments()
p.check_all_metrics()
p.show_legacy = True
html = requests.get(p.options.url).content
soup = BeautifulSoup(html)
activitylist = soup.find('div',
                         {'class': 'activityNumbers activityNumbersNew'})
activities = activitylist.findAll('div', recursive=False)

p.add_metric('metrics_found', value=len(activities), warn='0..1')
p.add_summary('%s metrics found on landspitali website' % (len(activities)))
Example #6
0
#!/usr/bin/python

import os.path
import sys

pynagbase = os.path.abspath(
    os.path.join(os.path.dirname(__file__), os.path.pardir))
sys.path[0] = pynagbase

# Standard init
from pynag.Plugins import PluginHelper, ok

# Create an instance of PluginHelper()
my_plugin = PluginHelper()

# Feed fake data for range checking
my_plugin.parser.add_option('-F',
                            dest='fakedata',
                            help='fake data to test thresholds')

# Activate
my_plugin.parse_arguments()

my_plugin.add_status(ok)
my_plugin.add_summary(my_plugin.options.fakedata)
my_plugin.add_metric('fakedata', my_plugin.options.fakedata)

my_plugin.check_all_metrics()
my_plugin.exit()