Giter VIP home page Giter VIP logo

check_katello_currency's Introduction

check_katello_currency

Example Icinga2 screenshot

check_katello_currency is a Nagios/Icinga plugin for checking patch currency of hosts managed by Foreman/Katello or Red Hat Satellite 6. As it also supports performance data, it can be used along with visualization tools such as Grafana:

Example Grafana screenshot

The script checks the patch currency of one or multiple systems. The following information are gathered by accesing the Foreman/Katello API:

  • Outstanding errata update counter per category:
    • bug fix
    • security
    • total summary

To gather these information a valid username / password combination to your management system is required. The login credentials are prompted when running the script. To automate this you have two options:

Setting shell variables

The following shell variables are used:

  • SATELLITE_LOGIN - a username
  • SATELLITE_PASSWORD - the appropriate password

You might also want to set the HISTFILE variable (depending on your shell) to hide the command including the password in the history:

$ HISTFILE="" SATELLITE_LOGIN=mylogin SATELLITE_PASSWORD=mypass ./check_katello_currency.py -S giertz.stankowic.loc

Using an authfile

A better possibility is to create a authfile with permisions 0600. Just enter the username in the first line and the password in the second line and hand the path to the script:

$ ./check_katello_currency.py -a giertz.auth -S giertz.stankowic.loc

Requirements

The plugin requires Python 2.6 or newer - it also requires the requests and simplejson modules. The plugin requires API version 2 - the script checks the API version and aborts if you are using a historic version of Foreman.

Usage

By default, the script checks a particular system or multiple systems for outstanding bugfix and security errata. It is possible to control this behaviour by specifying additional parameters (see below). The script also support performance data for data visualization.

The following parameters can be specified:

Parameter Description
-h / --help shows help and quits
-d / --debug enable debugging outputs (default: no)
-P / --show-perfdata enables performance data (default: no)
-a / --authfile defines an auth file to use instead of shell variables
-s / --server defines the server to use (default: localhost)
--insecure Disables SSL verification (default: no)
-y / --generic-statistics checks for inactive and outdated system statistic metrics (default :no)
-u / --outdated-warning defines outdated systems warning percentage threshold (default: 50)
-U / --outdated-critical defines outdated systems critical percentage threshold (default: 80)
-n / --inactive-warning defines inactive systems warning percentage threshold (default: 10)
-N / --inactive-critical defines inactive systems critical percentage threshold (default: 50)
-S / --system defines one or multiple system(s) to check
-A / --all-systems checks all registered systems - USE WITH CAUTION (default: no)
-x / --exclude specifices particular hosts to ignore (default: no)
-t / --total-warning defines total package update warning threshold (default: empty)
-T / --total-critical defines total package update critical threshold (default: empty)
-i / --important-warning defines security package (critical, important and moderate security fixes) update warning threshold (default: 10)
-I / --important-critical defines security package (critical, important and moderate security fixes) update warning threshold (default: 20)
-b / --bugs-warning defines bug package update warning threshold (default: 25)
-B / --bugs-critical defines bug package update warning threshold (default: 50)
-l / --location filters by a particular location (default: no)
-o / --organization filters by a particular organization (default: no)
-g / --hostgroup filters by a particular hostgroup (default: no)
-e / --environment filters by a particular environment (default: no)

Examples

The following example checks a single system on the local Foreman/Katello server:

$ ./check_katello_currency.py -S giertz.stankowic.loc
Satellite Username: admin
Satellite Password:
OK: bugfix errata OK (0), security errata OK (1) for host giertz.stankowic.loc

Checking multiple systems on a remote Foreman/Katello server, authentication using authfile:

$ ./check_katello_currency.py -s st-katello01.stankowic.loc -a katello.auth -S giertz.stankowic.loc -S shittyrobots.test.loc
OK: bugfix errata OK (0), security errata OK (1) for host giertz.stankowic.loc, bugfix errata OK (0), security errata OK (1) for host shittyrobots.test.loc

Checking a single host on a local Foreman/Katello installation, also checking total errata, enabling performance data:

$ ./check_katello_currency.py -S giertz.stankowic.loc -t 1 -T 20 -P
Username: admin
Password:
WARNING: bugfix errata OK (0), security errata OK (1), total errata WARNING (1) for host giertz.stankowic.loc | 'bugfix_errata'=0;25;50;; 'security_errata'=1;10;20;; 'total_errata'=1;1;20;;

When specifying multiple systems along with performance data, the metric names will get prefix according to the particular host:

$ ./check_katello_currency.py -S giertz.stankowic.loc -S shittyrobots.test.loc -a katello.auth -P
OK: bugfix errata OK (0), security errata OK (1) for host giertz.stankowic.loc, bugfix errata OK (0), security errata OK (1) for host shittyrobots.test.loc | 'bugfix_errata_giertz'=0;25;50;; 'security_errata_giertz'=1;10;20;; 'bugfix_errata_shittyrobots'=0;25;50;; 'security_errata_shittyrobots'=1;10;20;;

When checking all systems (which seriously fsckes up readability!) it is possible to filter by location, organization, hostgroup or Puppet environment. Both human-readable names and internal IDs are accepted:

$ ./check_katello_currency.py -s st-katello01.stankowic.loc -a katello.auth -A -g dev-hosts
OK: bugfix errata OK (0), security errata OK (0) for host st-devel02.stankowic.loc, bugfix errata OK (0), security errata OK (0) for host st-web04.stankowic.loc

Checking generic statistics of a Foreman/Katello system:

$ ./check_katello_currency.py -a katello.auth -y -P
OK: outdated systems OK (0), inactive systems OK (0)| 'systems_outdated'=0;;;; 'systems_total'=8;;;; 'systems_inactive'=0;;;;

Installation

Just deploy the Python script on your Icinga host or node. This repository also includes a NRPE and Icinga2 configuration. If you're using a RPM-based Linux distro, you can use the RPM spec file to create a RPM pacakge.

Icinga2 configuration idea

I'm using the following snippet to check all the update currency of all Linux VMs:

apply Service "DIAG: Katello currency" {
  import "generic-service"
  check_command = "check_katello_currency"
  vars.katello_perfdata = true
  vars.katello_host = "st-katello01.stankowic.loc"
  vars.katello_authfile = "/usr/lib64/nagios/plugins/katello.auth"
  assign where host.vars.os == "Linux"
  ignore where host.vars.app == "katello"
  ignore where host.vars.nokatello
  ignore where host.vars.noagent
}

Systems running the Foreman/Katello application as well as systems without the Icinga2 agent (or systems with the noagent flag) are ignored. To check the statistics on Foreman/Katello hosts, you could use the following snippet:

apply Service "DIAG: Katello statistics" {
  import "generic-service"
  check_command = "check_katello_currency"
  vars.katello_stats = true
  vars.katello_perfdata = true
  assign where host.vars.os == "Linux" && host.vars.app == "katello"
  ignore where host.vars.noagent
}

Systems running the Foreman/Katello application (implemented by the vars.app tag) will be checked. The vars.katello_stats flag automatically sets the -y parameter. Make sure the particular host configuration contains an authfile:

object Host "st-katello01.stankowic.loc" {
  import "linux-host"
...
  vars.app = "katello"
  vars.katello_authfile = "/usr/lib64/nagios/plugins/katello.auth"

The authfile needs to have file permissions 0600 and should be owned by the icinga user:

# chmod 0600 /usr/lib64/nagios/plugins/katello.auth
# chown icinga: /usr/lib64/nagios/plugins/katello.auth

check_katello_currency's People

Contributors

stdevel avatar

Watchers

 avatar  avatar

Forkers

donien

check_katello_currency's Issues

ValueError: unconverted data remains: +0200

Hi,
Also with this plugin (faced the first time with check_katello_sync), I face a date issue:

-bash-4.2$ /usr/lib64/nagios/plugins/check_katello_currency.py -s xxxxx -a /usr/lib64/nagios/plugins/katello.auth -y -P
Traceback (most recent call last):
  File "/usr/lib64/nagios/plugins/check_katello_currency.py", line 563, in <module>
    main(options)
  File "/usr/lib64/nagios/plugins/check_katello_currency.py", line 547, in main
    check_stats()
  File "/usr/lib64/nagios/plugins/check_katello_currency.py", line 209, in check_stats
    inactive_sys = [x for x in SYSTEM_ERRATA if is_inactive(SYSTEM_ERRATA[x]["updated_at"])]
  File "/usr/lib64/nagios/plugins/check_katello_currency.py", line 288, in is_inactive
    timestamp.replace(" UTC", ""), "%Y-%m-%d %H:%M:%S"
  File "/usr/lib64/python2.7/_strptime.py", line 328, in _strptime
    data_string[found.end():])
ValueError: unconverted data remains:  +0200
-bash-4.2$

Any idea how I can fix that?
BR,
Yannick

No connection adapters were found

Hi, I get this error:

./check_katello_currency.py --debug -a auth_sat.txt -s satellite -A
DEBUG:check_katello_currency:Options: Namespace(all_systems=True, authfile='auth_sat.txt', bugs_crit=50, bugs_warn=25, debug=True, environment='', exclude=[], gen_stats=False, hostgroup='', inactive_crit=50, inactive_warn=10, location='', organization='', outdated_crit=80, outdated_warn=50, security_crit=20, security_warn=10, server='satellite', show_perfdata=False, ssl_verify=True, system=[], total_crit=None, total_warn=None)
DEBUG:check_katello_currency:Arguments: None
DEBUG:check_katello_currency:Using authfile
DEBUG:check_katello_currency:File permission matches 0600
ERROR:ForemanAPIClient:No connection adapters were found for '[https://satellite/api/v2]https://satellite/api/v2/status?per_page=1337&page=1'
Traceback (most recent call last):
File "./check_katello_currency.py", line 600, in
main(options)
File "./check_katello_currency.py", line 576, in main
options.server, sat_user, sat_pass, options.ssl_verify
File "/root/ForemanAPIClient.py", line 87, in init
self.validate_api_support()
File "/root/ForemanAPIClient.py", line 244, in validate_api_support
self.api_get("/status")
File "/usr/lib64/python2.7/json/init.py", line 339, in loads
return _default_decoder.decode(s)
File "/usr/lib64/python2.7/json/decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: expected string or buffer

Error when checking currency of invalid content hosts

When checking an invalid content host (e.g. the Foreman/Katello host), the plugin crashes:

DEBUG:check_katello_currency:Checking system 'st-katello01.stankowic.loc'...
Traceback (most recent call last):
  File "./check_katello_currency.py", line 547, in <module>
    main(options)
  File "./check_katello_currency.py", line 533, in main
    check_systems()
  File "./check_katello_currency.py", line 87, in check_systems
    SYSTEM_ERRATA[system]["content_facet_attributes"]["errata_counts"]
KeyError: 'content_facet_attributes'

Generating generic statistics fails

Generating generic statistics fails:

Traceback (most recent call last):
  File "./check_katello_currency.py", line 562, in <module>
    main(options)
  File "./check_katello_currency.py", line 546, in main
    check_stats()
  File "./check_katello_currency.py", line 188, in check_stats
    bugs_warn = [x for x in SYSTEM_ERRATA if SYSTEM_ERRATA[x]["content_facet_attributes"]["errata_counts"]["bugfix"] >= options.bugs_warn]
KeyError: 'content_facet_attributes'

python-requests changed SSL default behavior

On some newer Python requests versions, the script is failing:

 File "/usr/lib64/nagios/plugins/ForemanAPIClient.py", line 339, in get_id_by_name
self.api_get("/{}s".format(api_object)) File "/usr/lib64/nagios/plugins/ForemanAPIClient.py", line 182, in
api_get return self.__api_request("get", sub_url, "", hits, page) File "/usr/lib64/nagios/plugin
/ForemanAPIClient.py", line 150, in __api_request headers=self.HEADERS File "/usr/lib/python2.7/site
packages/requests/sessions.py", line 476, in get return self.request('GET', url, **kwargs) File "/usr/li
/python2.7/site-packages/requests/sessions.py", line 464, in request resp = self.send(prep, **send_kwargs)
File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 576, in send r = adapter.send(request,
**kwargs) File "/usr/lib/python2.7/site-packages/requests/adapters.py", line 431, in send raise SSLError(e,
request=request) requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed
(_ssl.c:579)

It seems like newer module versions enforce SSL checking which has not been the default, yet. The affected library is ForemanAPIClient.

Generic statistics are broken if a system has no Katello agent installed

Checking generic statistics breaks if a system has no Katello agent (resulting in missing content_facet_attributes dictionary):

...
Traceback (most recent call last):
File "/usr/lib64/nagios/plugins/check_katello_currency", line 567, in <module>
    main(options)
  File "/usr/lib64/nagios/plugins/check_katello_currency", line 551, in main
    check_stats()
  File "/usr/lib64/nagios/plugins/check_katello_currency", line 188, in check_stats
    bugs_warn = [x for x in SYSTEM_ERRATA if SYSTEM_ERRATA[x]["content_facet_attributes"]["errata_counts"]["bugfix"] >= options.bugs_warn]
KeyError: 'content_facet_attributes'

Plugin dies in a fire when host non-existent

If a host does not exist, the plugin fails. Would be great to have an error message instead:

Traceback (most recent call last):
File "/usr/lib64/nagios/plugins/check_katello_currency.py", line 547, in <module>
    main(options)
  File "/usr/lib64/nagios/plugins/check_katello_currency.py", line 533, in main
    check_systems()
  File "/usr/lib64/nagios/plugins/check_katello_currency.py", line 87, in check_systems
    SYSTEM_ERRATA[system]["content_facet_attributes"]["errata_counts"]
KeyError: 'pinkepank.giertz.loc'

ERROR:ForemanAPIClient:zero length field name in format

./check_katello_currency.py -a repoauthfile -y -P
/usr/lib/python2.6/site-packages/argparse.py:1575: DeprecationWarning: The "version" argument to ArgumentParser is deprecated. Please use "add_argument(..., action='version', version="N", ...)" instead
"""instead""", DeprecationWarning)
ERROR:ForemanAPIClient:zero length field name in format
Traceback (most recent call last):
File "./check_katello_currency.py", line 600, in
main(options)
File "./check_katello_currency.py", line 576, in main
options.server, sat_user, sat_pass, options.ssl_verify
File "/root/scripts/satellite/check_katello_currency/ForemanAPIClient.py", line 87, in init
self.validate_api_support()
File "/root/scripts/satellite/check_katello_currency/ForemanAPIClient.py", line 244, in validate_api_support
self.api_get("/status")
File "/usr/lib64/python2.6/json/init.py", line 307, in loads
return _default_decoder.decode(s)
File "/usr/lib64/python2.6/json/decoder.py", line 319, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: expected string or buffer

System facts:
OS: RHEL 6
Satellite API v2
Python 2.6.6

Any hints/workarounds for this issue?

Performance data invalid when gathering data fails

When gathering errata information fails (see the None value), performance data is invalid:

warning/GraphiteWriter: Ignoring invalid perfdata value: total_errata=None;10;25;;
Context:
        (0) Processing check result for 'giertz.pinkepank.loc!DIAG: Katello currency'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.