Ejemplo n.º 1
0
    def __init__(
        self, usage=None, shortname=None, version=nagios.__version__, url=None,
            blurb=None, licence=lgpl3_licence_text, extra=None, plugin=None,
            timeout=default_timeout):
        """
        Constructor of the NagiosPlugin class.

        Instantiate object::

            from nagios.plugin import NagiosPlugin

            # Minimum arguments:
            na = NagiosPlugin(
                usage = 'Usage: %(prog)s --hello',
                version = '0.0.1',
            )

        @param usage: Short usage message used with --usage/-? and with missing
                      required arguments, and included in the longer --help
                      output. Can include %(prog)s placeholder which will be
                      replaced with the plugin name, e.g.::

                          usage = 'Usage: %(prog)s -H <hostname> -p <ports> [-v]'

        @type usage: str
        @param shortname: the shortname of the plugin
        @type shortname: str
        @param version: Plugin version number, included in the --version/-V
                        output, and in the longer --help output. e.g.::

                            $ ./check_tcp_range --version
                            check_tcp_range 0.2 [http://www.openfusion.com.au/labs/nagios/]
        @type version: str
        @param url: URL for info about this plugin, included in the
                    --version/-V output, and in the longer --help output.
                    Maybe omitted.
        @type url: str or None
        @param blurb: Short plugin description, included in the longer
                      --help output. Maybe omitted.
        @type blurb: str or None
        @param licence: License text, included in the longer --help output. By
                        default, this is set to the standard nagios plugins
                        LGPLv3 licence text.
        @type licence: str or None
        @param extra: Extra text to be appended at the end of the longer --help
                      output, maybe omitted.
        @type extra: str or None
        @param plugin: Plugin name. This defaults to the basename of your plugin.
        @type plugin: str or None
        @param timeout: Timeout period in seconds, overriding the standard
                        timeout default (15 seconds).
        @type timeout: int

        """

        self._shortname = shortname
        if self._shortname:
            self._shortname = self._shortname.strip()
        if not self._shortname:
            self._shortname = get_shortname(plugin=plugin)

        self.argparser = None
        if usage:
            self.argparser = NagiosPluginArgparse(
                usage=usage,
                version=version,
                url=url,
                blurb=blurb,
                licence=licence,
                extra=extra,
                plugin=plugin,
                timeout=timeout,
            )

        self.perfdata = []

        self.messages = {
            'warning': [],
            'critical': [],
            'ok': [],
        }

        self.threshold = None
Ejemplo n.º 2
0
            help=('Show details for command-line debugging (can repeat up to 3 times)'),
        )

# =============================================================================

if __name__ == "__main__":

    from nagios.plugin.functions import get_shortname
    from nagios.color_syslog import ColoredFormatter

    verbose = 0
    if '-v' in sys.argv:
        verbose = 1
        verbose = sys.argv.count('-v')

    shortname = get_shortname()

    root_log = logging.getLogger()
    root_log.setLevel(logging.INFO)
    if verbose:
        root_log.setLevel(logging.DEBUG)

    format_str = shortname + ': '
    if verbose:
        if verbose > 1:
            format_str += '%(name)s(%(lineno)d) %(funcName)s() '
        else:
            format_str += '%(name)s '
    format_str += '%(levelname)s - %(message)s'
    formatter = None
    if verbose: