Coder Social home page Coder Social logo

stdevel / check_katello_sync Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 4.0 33 KB

A Nagios / Icinga plugin for checking product synchronization within Katello/Red Hat Satellite 6.x

License: GNU General Public License v3.0

Python 100.00%
icinga icinga2 icinga-plugin icinga2-plugin katello foreman system-information satellite satellite6

check_katello_sync's Introduction

check_katello_sync

check_katello_sync is a Nagios/Icinga plugin for checking product synchronization within Katello/Red Hat Satellite 6.x. It also supports performance data, enabling visualizing results with tools such as Grafana.

The script checks the synchronization of one or multiple product of an organization.

To gather 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_sync.py -s giertz.stankowic.loc

Using an authfile

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

$ ./check_katello_sync.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/Katello.

Usage

By default, the script checks the synchronization of all products of an particular organization. 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)
-o / --organization specifies the organization to check (name or ID)
-w / --outdated-warning defines outdated products warning threshold in days (default: 2)
-c / --outdated-critical defines outdated products critical threshold in days (default: 5)
-i / --include specifies particular products to check (default: no)
-e / --exclude specifies particular products to ignore (default: no)

Examples

The following example checks all products of an particular organization on a Foreman/Katello server:

$ ./check_katello_sync.py -s st-katello01.stankowic.loc -o Stankowic
Satellite Username: admin
Satellite Password:
CRITICAL: Products outdated more than 5 days: Stankowic_Puppet. Products outdated up to 2 days: Stankowic_Docker. Products synchronized: owncloud-el7-x86_64, katello-client-el7-x86_64, icinga2-el7-x86_64, grafana-el7-x86_64, gitlab-ci-el7-x86_64, EPEL_7_x86_64, CentOS_7_x86_64 |

Ignoring some products synchronized manually, authentication using authfile:

$ ./check_katello_sync.py -s st-katello01.stankowic.loc -a giertz.auth -o Stankowic -e Stankowic_Puppet -e Stankowic_Docker
OK: Products synchronized: owncloud-el7-x86_64, katello-client-el7-x86_64, icinga2-el7-x86_64, grafana-el7-x86_64, gitlab-ci-el7-x86_64, EPEL_7_x86_64, CentOS_7_x86_64 |

Only checking some particular products, enabling performance data:

$ ./check_katello_sync.py -s st-katello01.stankowic.loc -a shittyrobots.auth -o Stankowic -i gitlab-ci-el7-x86_64 -P
OK: Products synchronized: gitlab-ci-el7-x86_64 | 'prod_total'=9;;;; 'prod_warn'=0;2;2;; 'prod_crit'=0;5;5;;

The same, specifying custom thresholds:

$ ./check_katello_sync.py -s st-katello01.stankowic.loc -a pinkepank.auth -o Stankowic -i gitlab-ci-el7-x86_64 -P -w 2 -c 4
OK: Products synchronized: gitlab-ci-el7-x86_64 | 'prod_total'=9;;;; 'prod_warn'=0;2;2;; 'prod_crit'=0;4;4;;

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 the products of my Foreman/Katello servers:

apply Service "DIAG: Katello product synchronization" {
  import "generic-service"
  check_command = "check_katello_sync"
  vars.katello_perfdata = true
  vars.katello_host = "st-katello01.stankowic.loc"
  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. Make sure the particular host configuration contains an authfile and organization:

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

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

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

To include or exclude products, you can utilize the products_include or products_exclude variables. When using the include variable, only defined products will be checked. Specifying the exclude variable will check all products except those mentioned in the variable.

To exclude particular products, alter your configuration like this:

  vars.products_exclude = ["Stankowic_Docker", "Stankowic_Puppet"]

To only check particular products, use this one:

  vars.products_include = ["CentOS_7_x86_64"]

check_katello_sync's People

Contributors

dgoetz avatar donien avatar stdevel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

check_katello_sync's Issues

ValueError: time data '2017-05-03 06:00:29 +0200' does not match format '%Y-%m-%d %H:%M:%S UTC'

Hello,
Apparently I'm facing a date format issue:

-bash-4.2$ /usr/lib64/nagios/plugins/check_katello_sync.py -s xxxxx -o yyyyy -a /usr/lib64/nagios/plugins/katello.auth
Traceback (most recent call last):
  File "/usr/lib64/nagios/plugins/check_katello_sync.py", line 354, in <module>
    main(options)
  File "/usr/lib64/nagios/plugins/check_katello_sync.py", line 339, in main
    check_products()
  File "/usr/lib64/nagios/plugins/check_katello_sync.py", line 148, in check_products
    check_product(product)
  File "/usr/lib64/nagios/plugins/check_katello_sync.py", line 106, in check_product
    product["last_sync"], "%Y-%m-%d %H:%M:%S UTC"
  File "/usr/lib64/python2.7/_strptime.py", line 325, in _strptime
    (data_string, format))
ValueError: time data '2017-05-03 06:00:29 +0200' does not match format '%Y-%m-%d %H:%M:%S UTC'
-bash-4.2$ 

Is there a way to fix that?
BR,
Yannick

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.

UTF-8 characters in repo description break check script

If there is a repo containing UTF-8 characters in it's description, the script fails with the following error:

Traceback (most recent call last):
  File "./check_katello_sync.py", line 370, in <module>
    main(options)
  File "./check_katello_sync.py", line 355, in main
    check_products()
  File "./check_katello_sync.py", line 158, in check_products
    check_product(product)
  File "./check_katello_sync.py", line 106, in check_product
    product["label"], product["description"], product["last_sync"][0:19]
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 322: ordinal not in range(128)

This is caused by:

LOGGER.debug("Product '{0}' ({1}) was synced at {2}".format(
product["label"], product["description"], product["last_sync"][0:19]

If this line is changed to the following, the script works again:

        LOGGER.debug("Product '{0}' ({1}) was synced at {2}".format(
            product["label"], (product["description"] or '').encode('utf8'), product["last_sync"][0:19]

Non-existent included products are not evaluated

When checking non-existing products, no error is displayed:

$ ./check_katello_sync --insecure -o giertz -s mysat.localhost.loc -i pinkepank -a mysat.auth
OK:  |

There should be an error message.

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.