#917 copr: nagios check for Copr's CDN
Merged 2 years ago by praiskup. Opened 2 years ago by schlupov.
fedora-infra/ schlupov/ansible check_copr_cdn  into  main

@@ -172,3 +172,25 @@ 

      line: 'OPTIONS=--collector.textfile.directory /var/lib/node_exporter/textfile_collector --collector.systemd'

      backrefs: yes

    notify: restart node_exporter

+ 

+ - name: install nrpe

+   dnf: name=nrpe state=present

+ 

+ - name: install nrpe checks

+   template: src=copr_frontend_nrpe.cfg

+             dest=/etc/nrpe.d/copr_frontend_nrpe.cfg

+   notify:

+   - restart nrpe

+   tags:

+   - nagios_client

+   - copr_cdn

+ 

+ - name: install the check script

+   template:

+     dest: "/usr/bin/copr-cdn-check.py"

+     src: "copr-cdn-check.py.j2"

+     group: "nagios"

+     mode: 0750

+   vars:

+     api_key: "{{ copr_cdn_api_key }}"

+   tags: copr_cdn

@@ -0,0 +1,92 @@ 

+ import sys

+ import requests

+ import logging

+ 

+ # NAGIOS exit codes

+ NAG_UNKNOWN = 3

+ NAG_CRITICAL = 2

+ NAG_WARNING = 1

+ NAG_OK = 0

+ 

+ # UptimeRobot statuses

+ STATUS = (

+     'PAUSED',  # 0

+     'NOT_CHECKED_YET',  # 1

+     'UP',  # 2

+     'NOT_USED',  # 3

+     'NOT_USED',  # 4

+     'NOT_USED',  # 5

+     'NOT_USED',  # 6

+     'NOT_USED',  # 7

+     'SEEMS_DOWN',  # 8

+     'DOWN'  # 9

+ )

+ 

+ # Read only API key

+ API_KEY = "{{ api_key }}"

+ 

+ logging.basicConfig(

+     level=logging.INFO,

+     format='%(message)s',

+     handlers=[logging.StreamHandler(sys.stdout)],

+ )

+ LOG = logging.getLogger()

+ 

+ 

+ class UptimeRobot:

+ 

+     def __init__(self, api_key):

+         self.api_key = api_key

+ 

+     def post(self, method='getMonitors'):

+         """Send the post request to UptimeRobot api"""

+         url = "https://api.uptimerobot.com/v2/{method}".format(method=method)

+         payload = "api_key={api_key}&format=json".format(api_key=self.api_key)

+         headers = {

+             'content-type': "application/x-www-form-urlencoded",

+             'cache-control': "no-cache"

+         }

+         response = requests.request("POST", url, data=payload, headers=headers)

+         return response.json()

+ 

+     def get_monitor(self, name):

+         """Return specific monitor"""

+         monitors = self.post('getMonitors')

+         if 'monitors' not in monitors:

+             return None

+ 

+         for monitor in monitors['monitors']:

+             if monitor['friendly_name'] == name:

+                 return {'name': name,

+                         'print_status': STATUS[monitor['status']],

+                         'status': monitor['status'],

+                         'url': monitor['url']

+                         }

+         return None

+ 

+ 

+ def main():

+     monitor_name = "Copr's CDN"

+     uptime_robot = UptimeRobot(API_KEY)

+ 

+     monitor = uptime_robot.get_monitor(monitor_name)

+     if monitor:

+         result = "{name} ({url}) is {status}".format(name=monitor['name'], url=monitor['url'],

+                                                      status=monitor['print_status'])

+         if monitor['status'] in (0, 1):

+             LOG.warning(result)

+             sys.exit(NAG_WARNING)

+         elif monitor['status'] in (8, 9):

+             LOG.critical(result)

+             sys.exit(NAG_CRITICAL)

+         elif monitor['status'] == 2:

+             LOG.info(result)

+             sys.exit(NAG_OK)

+         else:

+             LOG.critical(result)

+             sys.exit(NAG_UNKNOWN)

+ 

+ 

+ if __name__ == "__main__":

+     main()

+     sys.exit(NAG_UNKNOWN)

@@ -0,0 +1,1 @@ 

+ command[check_copr_cdn]=/usr/bin/copr-cdn-check.py

@@ -32,3 +32,10 @@ 

      check_command          check_by_nrpe!check_copr_ping

      use                    defaulttemplate

  }

+ 

+ define service {

+     hostgroup_name         copr_front_aws, copr_front_dev_aws

+     service_description    The copr cdn status

+     check_command          check_by_nrpe!check_copr_cdn

+     use                    defaulttemplate

+ }

@@ -320,6 +320,7 @@ 

  command[check_nagios]=/usr/lib64/nagios/plugins/check_nagios -e 5 -F /var/spool/nagios/status.dat -C /usr/sbin/nagios

  command[check_auditd]=/usr/lib64/nagios/plugins/check_procs -c 1:1 -C 'auditd' -u root

  command[check_copr_ping]=/usr/bin/copr-ping-check.py

+ command[check_copr_cdn]=/usr/bin/copr-cdn-check.py

  command[check_cron]=/usr/lib64/nagios/plugins/check_procs -c 1:10 -C 'crond' -u root

  command[check_varnish_proc]=/usr/lib64/nagios/plugins/check_procs -c 1:2 -C 'varnishd' -u varnish

  command[check_rsyslogd_proc]=/usr/lib64/nagios/plugins/check_procs -c 1:2 -C 'rsyslogd'