check_zypper.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. #############################################################################
  3. # (c) 2011 Sven Velt <sven@velt.de #
  4. # and team(ix) GmbH, Nuernberg, Germany #
  5. # #
  6. # This file is part of "team(ix) Monitoring Plugins" #
  7. # URL: http://oss.teamix.org/projects/monitoringplugins/ #
  8. # #
  9. # All rights reserved. #
  10. # Redistribution and use in source and binary forms, with or without #
  11. # modification, are permitted provided that the following conditions #
  12. # are met: #
  13. # 1. Redistributions of source code must retain the above copyright #
  14. # notice, this list of conditions and the following disclaimer. #
  15. # 2. Redistributions in binary form must reproduce the above copyright #
  16. # notice, this list of conditions and the following disclaimer in the #
  17. # documentation and/or other materials provided with the distribution. #
  18. # 3. The name of the copyright owner may not be used to endorse or #
  19. # promote products derived from this software without specific prior #
  20. # written permission. #
  21. # #
  22. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR #
  23. # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED #
  24. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE #
  25. # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, #
  26. # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES #
  27. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR #
  28. # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) #
  29. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, #
  30. # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING #
  31. # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE #
  32. # POSSIBILITY OF SUCH DAMAGE. #
  33. #############################################################################
  34. # Works on:
  35. # - SLES 11
  36. # Does NOT work on:
  37. # -
  38. # From "/etc/sudoers" / "visudo":
  39. # nagios ALL = NOPASSWD: /usr/bin/zypper ref,/usr/bin/zypper -q pchk
  40. #
  41. if [ ! -x /usr/bin/zypper ] ; then
  42. echo 'Zypper CRITICAL - Zypper not found!'
  43. exit 2
  44. fi
  45. # Refresh repositories
  46. sudo /usr/bin/zypper ref >/dev/null 2>&1
  47. zypper_out=$(sudo LANG=C /usr/bin/zypper -q pchk)
  48. if ( echo "${zypper_out}" | grep -q "needed" ) ; then
  49. output=$(echo ${zypper_out} | cut -d "." -f 7)
  50. patches=$(echo ${output} | cut -d " " -f1)
  51. if [ ${patches} -gt 0 ] ; then
  52. secpatches=$(echo ${output} | cut -d "(" -f2|cut -d " " -f1)
  53. if [ -n "${secpatches}" ]; then
  54. if [ ${secpatches} -gt 0 ] ; then
  55. echo "Zypper CRITICAL - ${patches}"
  56. exit 2
  57. fi
  58. echo "Zypper WARNING - ${output}"
  59. exit 1
  60. fi
  61. fi
  62. fi
  63. echo "Zypper OK - No updates available"
  64. exit 0