check_systemd_units 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/bash
  2. # Copyright (C) 2016 Mohamed El Morabity <melmorabity@fedoraproject.com>
  3. #
  4. # This module is free software: you can redistribute it and/or modify it under
  5. # the terms of the GNU General Public License as published by the Free Software
  6. # Foundation, either version 3 of the License, or (at your option) any later
  7. # version.
  8. #
  9. # This software is distributed in the hope that it will be useful, but WITHOUT
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License along with
  14. # this program. If not, see <http://www.gnu.org/licenses/>.
  15. PLUGINDIR=/usr/lib/nagios/plugins/
  16. . $PLUGINDIR/utils.sh
  17. status=$(systemctl list-units --failed --no-legend --plain | cut -f1 -d" " |xargs)
  18. r=$?
  19. while getopts "w" opt; do
  20. case $opt in
  21. w)
  22. # Whitelist einlesen
  23. readarray -t units < /etc/icinga2/service_whitelist
  24. esac
  25. status=( $(systemctl list-units --failed --no-legend --plain ${units[*]}| cut -f1 -d" " |xargs) )
  26. r=$?
  27. done
  28. if [ $r -ne 0 ]; then
  29. echo "UNKNOWN: Check command failed."
  30. exit $STATE_UNKNOWN
  31. fi
  32. if [ -z "$status" ]; then
  33. echo "OK: No Failed Units."
  34. exit $STATE_OK
  35. else
  36. echo "CRITICAL: Some units failed. ${status[*]}."
  37. exit $STATE_CRITICAL
  38. fi
  39. echo "OK: service $service is running"
  40. exit $STATE_OK