{"id":21260330,"url":"https://github.com/nlm/nagplug","last_synced_at":"2025-07-11T03:31:05.817Z","repository":{"id":16822193,"uuid":"19581409","full_name":"nlm/nagplug","owner":"nlm","description":"Nagios Plugin creation library for Python","archived":false,"fork":false,"pushed_at":"2024-07-17T14:28:53.000Z","size":49,"stargazers_count":3,"open_issues_count":4,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-07T08:11:38.647Z","etag":null,"topics":["icinga","monitoring","nagios","python","threshold"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nlm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2014-05-08T16:56:24.000Z","updated_at":"2022-05-19T22:58:05.000Z","dependencies_parsed_at":"2024-01-08T18:03:45.393Z","dependency_job_id":"a402383a-01bd-4cc7-b1fd-7feae310a265","html_url":"https://github.com/nlm/nagplug","commit_stats":{"total_commits":53,"total_committers":2,"mean_commits":26.5,"dds":"0.018867924528301883","last_synced_commit":"a0ab85fd33737b150eac2a902c45ec3233bb930c"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/nlm/nagplug","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlm%2Fnagplug","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlm%2Fnagplug/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlm%2Fnagplug/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlm%2Fnagplug/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nlm","download_url":"https://codeload.github.com/nlm/nagplug/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlm%2Fnagplug/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264721298,"owners_count":23653915,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["icinga","monitoring","nagios","python","threshold"],"created_at":"2024-11-21T04:17:44.001Z","updated_at":"2025-07-11T03:31:05.571Z","avatar_url":"https://github.com/nlm.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Nagplug ![Build Status](https://img.shields.io/travis/nlm/nagplug.svg) ![GitHub release](https://img.shields.io/github/release/nlm/nagplug.svg) ![PyPI](https://img.shields.io/pypi/v/nagplug.svg) [![License: MIT](https://img.shields.io/github/license/nlm/parseable.svg)](https://opensource.org/licenses/MIT)\n=======\n\nA library to easily write Monitoring Plugins compliant with the\n[monitoring plugins guidelines](https://www.monitoring-plugins.org/doc/guidelines.html)\nusing python.\n\nThis library was designed to be similar to Perl\n[Monitoring::Plugin library](http://search.cpan.org/~nierlein/Monitoring-Plugin-0.39/lib/Monitoring/Plugin.pm).\n\nPlugin Documentation\n--------------------\n\nYou can access embedded plugin documentation using pydoc\n\n    $ pydoc nagplug\n\nAlso, the `example.py` file gives a pretty good example of a simple plugin.\n\nThe nagplug library manages almost all the life of the plugin program,\nfrom argument parsing to timeouts, exception handling, output formatting.\n\nUsing the library\n-----------------\n\nFirst, create an instance of a Plugin\n\n```python\n\u003e\u003e\u003e from nagplug import Plugin, OK, WARNING, CRITICAL, UNKNOWN\n\u003e\u003e\u003e plugin = Plugin()\n\n```\n\nThen, you can add some arguments to parse from the command-line.\n(Note that unless you use `add_stdargs=False` when calling Plugin(),\nsome default standard arguments will be added\n(`--hostname`, `--timeout`, `--verbose` and `--version`).\n`--help` is added by the underlying `argparse` module.)\n\n```python\n\u003e\u003e\u003e plugin.add_arg('--max', required=True, type=int) # doctest: +ELLIPSIS\n_StoreAction(...)\n\u003e\u003e\u003e plugin.add_arg('--value', required=True, type=int) # doctest: +ELLIPSIS\n_StoreAction(...)\n\u003e\u003e\u003e args = plugin.parse_args('--max 3 --value 6'.split())\n\u003e\u003e\u003e print(args.max)\n3\n\u003e\u003e\u003e print(args.value)\n6\n\n```\n\nAny argument you can pass to `argparse.ArgumentParser.add_argument` can also\nbe passed to `nagplug.Plugin.add_arg`. See the `argparse` documentation to\nsee how it works and all the nice things you can do.\n\nIf you need to do advanced parsing, you can access the internal parser\nusing the `parser` attribute of the plugin.\n\n```python\n\u003e\u003e\u003e # if you want to add subparsers, for example.\n\u003e\u003e\u003e sp = plugin.parser.add_subparsers()\n\n```\n\nFor safety reasons, you might want your test to stop after a certain amount\nof time, considering that it failed. By default it will use the value of\n`args.timeout` set by the `--timeout` argument.\n\n```python\n\u003e\u003e\u003e print(args.timeout)\n30\n\u003e\u003e\u003e plugin.set_timeout()\n\n```\n\nNow let's say that you want to check if `value` is inferior to `max`,\nreturning an OK status if it's the case and critical if its is not.\nYou do the check, then add the result to the plugin.\nAt anytime, you can get the current plugin status via the `get_code()` method.\n\n```python\n\u003e\u003e\u003e if args.value \u003c= args.max:\n...     plugin.add_result(OK, 'All Good !')\n... else:\n...     plugin.add_result(CRITICAL, 'Dammit !')\n\u003e\u003e\u003e plugin.get_code() == CRITICAL\nTrue\n\u003e\u003e\u003e plugin.get_message()\n'Dammit !'\n\n```\n\nYou can add any number of results, the plugin will return the worst\nrecorded status:\n\n```python\n\u003e\u003e\u003e plugin.add_result(OK, 'But... Other test worked !')\n\u003e\u003e\u003e plugin.get_code() == CRITICAL\nTrue\n\n```\n\nWhen you're done, exit the plugin and return the final result\nby calling the `finish` method:\n\n```python\n\u003e\u003e\u003e plugin.finish() # doctest: +SKIP\n\n```\n\nChecking values against Thresholds\n----------------------------------\n\nThresholds are useful for the user to express more complex value ranges\nfrom the command line. The syntax is described in the\n[threshold format specification](https://www.monitoring-plugins.org/doc/guidelines.html#THRESHOLDFORMAT).\n\nThe `check_threshold` function makes it easy to check values against thresholds.\nIt returns the code corresponding to the worst threshold matched.\n\n```python\n\u003e\u003e\u003e from nagplug import Threshold\n\u003e\u003e\u003e warn_t = Threshold(':90')\n\u003e\u003e\u003e crit_t = Threshold(':95')\n\u003e\u003e\u003e plugin.check_threshold(56, warning=warn_t, critical=crit_t) == OK\nTrue\n\u003e\u003e\u003e plugin.check_threshold(93, warning=warn_t, critical=crit_t) == WARNING\nTrue\n\u003e\u003e\u003e plugin.check_threshold(97, warning=warn_t, critical=crit_t) == CRITICAL\nTrue\n\n```\n\nPerfdata and Extended Data\n--------------------------\n\nSome monitoring systems can also do graphing.\nThese system use the\n[performance data](https://www.monitoring-plugins.org/doc/guidelines.html#AEN201)\nemitted by your plugin.\n\nThe `add_perfdata` method will make sure everything is well-formatted.\nYou must give at least a label and a value, but you can also add an\nunit of measurement, minimum and maximum bounds, and thresholds.\n\n```python\n\u003e\u003e\u003e plugin.add_perfdata('percent_used', 20, uom='%', minimum=0, maximum=100)\n\u003e\u003e\u003e plugin.add_perfdata('age_of_the_captain', 87)\n\u003e\u003e\u003e print(plugin.get_perfdata())\n'percent_used'=20%;;;0;100 'age_of_the_captain'=87;;;;\n\n```\n\nExtended data can help you by having more details in your output,\nwhile keeping the main status line short and clear.\n\n```python\n\u003e\u003e\u003e plugin = Plugin()\n\u003e\u003e\u003e plugin.add_extdata('This will be logged in the output')\n\u003e\u003e\u003e plugin.add_extdata('This will also be logged')\n\u003e\u003e\u003e print(plugin.get_extdata())\nThis will be logged in the output\nThis will also be logged\n\n```\n\nThe `extdata_log_handler` method returns a convenient `LogHandler` for\nPython's `logging` framework that registers all output logs as extdata.\n\n```python\n\u003e\u003e\u003e import logging\n\u003e\u003e\u003e log = logging.getLogger()\n\u003e\u003e\u003e log.level = logging.DEBUG\n\u003e\u003e\u003e plugin = Plugin()\n\u003e\u003e\u003e log.addHandler(plugin.extdata_log_handler())\n\u003e\u003e\u003e log.info('This log will be registered as extdata')\n\u003e\u003e\u003e log.debug('This one also')\n\u003e\u003e\u003e print(plugin.get_extdata())\nThis log will be registered as extdata\nThis one also\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnlm%2Fnagplug","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnlm%2Fnagplug","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnlm%2Fnagplug/lists"}