Browse code

Poprawki z czujce dnf

Lukasz P authored on27/02/2021 15:41:18
Showing4 changed files
... ...
@@ -10,3 +10,11 @@
10 10
       minute: "*/10"
11 11
       job: "/usr/bin/touch /var/local/check_cron &> /dev/null"
12 12
 
13
+
14
+  - name: Write number of updates to files for monitoring
15
+    cron:
16
+      name: "check number of updates"
17
+      minute: "*/20"
18
+      job: "LANG=C /usr/bin/dnf -q updateinfo list > /var/local/check_dnf_updates 2>/dev/null"
19
+    when: ansible_os_family == 'RedHat'
20
+
... ...
@@ -7,21 +7,28 @@ if ! [ -x /usr/bin/dnf ] ; then
7 7
 fi
8 8
 
9 9
 # number of bug fixes
10
-nobf=$(eval "dnf -q updateinfo list | grep bugfix | wc -l")
10
+noup=$(eval "cat /var/local/check_dnf_updates | wc -l")
11 11
 
12 12
 # number of security fixes
13
-nosf=$(eval "dnf -q updateinfo list | grep secutiry | wc -l")
13
+nosf=$(eval "cat /var/local/check_dnf_updates | grep -E 'security|Sec\.' | wc -l")
14 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
15
+function check_dnf {
16
+  # print security fixes
17
+  if [ ${nosf} -gt 0 ] ; then
18
+    echo -n 'CRITICAL - ' 
19
+    echo -n ${nosf}
20
+    echo ' security fixes. '
21
+    return 2
22
+  elif [ ${noup} -gt 0 ] ; then
23
+    echo -n 'OK - '
24
+    echo -n ${noup}
25
+    echo ' updates'
26
+    return 1
27
+  else
28
+    echo 'OK - system up2date.'
29
+    return 0
30
+  fi
31
+}
32
+
33
+check_dnf
27 34
 
... ...
@@ -43,16 +43,16 @@ define service{
43 43
 }
44 44
 
45 45
 define service{
46
-    use                     bindir-service
46
+    use                     bindir-service-hourly
47 47
     host_name               {{ item.host_name }}
48 48
     service_description     APT
49 49
     check_command           check_nrpe!-c check_apt
50 50
 }
51 51
 
52 52
 define service{
53
-    use                     bindir-service
53
+    use                     bindir-service-hourly
54 54
     host_name               {{ item.host_name }}
55 55
     service_description     DNF
56
-    check_command           check_nrpe!-t 30 -c check_dnf
56
+    check_command           check_nrpe!-c check_dnf
57 57
 }
58 58
 
... ...
@@ -1,11 +1,15 @@
1 1
 # Managed with Ansible
2
+
2 3
 command[check_load]={{ item.plugin_path }}/check_load -w "$(($(nproc --all)))" -c "$(($(nproc --all)+1))"
3 4
 command[check_disk]={{ item.plugin_path }}/check_disk / -w 20% -c 10%
4 5
 command[check_swap]={{ item.plugin_path }}/check_swap -w 30% -c 10% -n ok
5 6
 command[check_cron]={{ item.plugin_path }}/check_file_age -w 610 -c 1210 -W 0 -C 0 -f /var/local/check_cron
6 7
 
8
+
9
+# --- wrappers ---
10
+
7 11
 command[check_apt]=/usr/local/bin/check_apt_wrapper 2>/dev/null
8 12
 
9
-# Beware of SELinux preventing nagios from using dnf
13
+# Beware of SELinux preventing nrpe from using dnf
10 14
 command[check_dnf]=/usr/local/bin/check_dnf_wrapper 2>/dev/null
11 15