Browse code

Monitoring dnf

Lukasz P authored on18/02/2021 17:13:52
Showing5 changed files
... ...
@@ -27,6 +27,7 @@
27 27
       - tree
28 28
       - net-tools
29 29
       - python3-policycoreutils
30
+      - policycoreutils-python-utils
30 31
       state: latest
31 32
       enablerepo: epel-modular,epel
32 33
     when: ansible_os_family == 'RedHat'
... ...
@@ -30,4 +30,31 @@
30 30
       group: nagios
31 31
       mode: 0750
32 32
     when: ansible_os_family == 'Suse'
33
+
34
+  - name: Copy check_dnf wrapper to Debian-like hosts
35
+    template:
36
+      src: ../templates/monitoring/check_dnf_wrapper
37
+      dest: /usr/local/bin/check_dnf_wrapper
38
+      owner: root
39
+      group: nagios
40
+      mode: 0750
41
+    when: ansible_os_family == 'Debian'
42
+  
43
+  - name: Copy check_dnf wrapper to Redhat-like hosts
44
+    template:
45
+      src: ../templates/monitoring/check_dnf_wrapper
46
+      dest: /usr/local/bin/check_dnf_wrapper
47
+      owner: root
48
+      group: nrpe
49
+      mode: 0750
50
+    when: ansible_os_family == 'RedHat'
33 51
   
52
+  - name: Copy check_dnf wrapper to Suse hosts
53
+    template:
54
+      src: ../templates/monitoring/check_dnf_wrapper
55
+      dest: /usr/local/bin/check_dnf_wrapper
56
+      owner: root
57
+      group: nagios
58
+      mode: 0750
59
+    when: ansible_os_family == 'Suse'
60
+
34 61
new file mode 100644
... ...
@@ -0,0 +1,27 @@
1
+#!/bin/bash
2
+# Managed with Ansible
3
+
4
+if ! [ -x /usr/bin/dnf ] ; then
5
+  echo "OK - not a Redhat."
6
+  exit 0
7
+fi
8
+
9
+# number of bug fixes
10
+nobf=$(eval "dnf -q updateinfo list | grep bugfix | wc -l")
11
+
12
+# number of security fixes
13
+nosf=$(eval "dnf -q updateinfo list | grep secutiry | wc -l")
14
+
15
+# print security fixes
16
+if [ ${nosf} -gt 0 ] ; then
17
+  echo -n 'CRITICAL - ' 
18
+  echo -n ${nosf}
19
+  echo ' security fixes. '
20
+elif [ ${nobf} -gt 0 ] ; then
21
+  echo -n 'OK - '
22
+  echo -n ${nobf}
23
+  echo ' bugfixes'
24
+else
25
+  echo 'OK - system up2date.'
26
+fi
27
+
... ...
@@ -18,34 +18,41 @@ define service {
18 18
     use                     bindir-service
19 19
     host_name               {{ item.host_name }}
20 20
     service_description     DISK_ROOT
21
-    check_command           check_nrpe!check_disk
21
+    check_command           check_nrpe!-c check_disk
22 22
 }
23 23
 
24 24
 define service{
25 25
     use                     bindir-service
26 26
     host_name               {{ item.host_name }}
27 27
     service_description     LOAD
28
-    check_command           check_nrpe!check_load
28
+    check_command           check_nrpe!-c check_load
29 29
 }
30 30
 
31 31
 define service{
32 32
     use                     bindir-service
33 33
     host_name               {{ item.host_name }}
34 34
     service_description     SWAP
35
-    check_command           check_nrpe!check_swap
35
+    check_command           check_nrpe!-c check_swap
36 36
 }
37 37
 
38 38
 define service{
39 39
     use                     bindir-service
40 40
     host_name               {{ item.host_name }}
41 41
     service_description     CRON
42
-    check_command           check_nrpe!check_cron
42
+    check_command           check_nrpe!-c check_cron
43 43
 }
44 44
 
45 45
 define service{
46 46
     use                     bindir-service
47 47
     host_name               {{ item.host_name }}
48 48
     service_description     APT
49
-    check_command           check_nrpe!check_apt
49
+    check_command           check_nrpe!-c check_apt
50
+}
51
+
52
+define service{
53
+    use                     bindir-service
54
+    host_name               {{ item.host_name }}
55
+    service_description     DNF
56
+    check_command           check_nrpe!-t 30 -c check_dnf
50 57
 }
51 58
 
... ...
@@ -4,5 +4,8 @@ command[check_disk]={{ item.plugin_path }}/check_disk / -w 20% -c 10%
4 4
 command[check_swap]={{ item.plugin_path }}/check_swap -w 30% -c 10% -n ok
5 5
 command[check_cron]={{ item.plugin_path }}/check_file_age -w 610 -c 1210 -W 0 -C 0 -f /var/local/check_cron
6 6
 
7
-command[check_apt]=/usr/local/bin/check_apt_wrapper
7
+command[check_apt]=/usr/local/bin/check_apt_wrapper 2>/dev/null
8
+
9
+# Beware of SELinux preventing nagios from using dnf
10
+command[check_dnf]=/usr/local/bin/check_dnf_wrapper 2>/dev/null
8 11