使用shinken、check_apt和event_handler更新服务器



我想知道Shinken的重要更新。我使用check_apt,但它返回我0更新,但当有更新。然后,我想在警报达到临界状态时启动一个event_handler。这些是文件:commands.cfg

# 'check_apt' command definition
define command {
    command_name    check_apt
    command_line    /usr/local/shinken/libexec/check_apt
    }
 define command {
  command_name    upgrade_server
  command_line    sudo /usr/local/shinken/libexec/upgrade $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$

script upgrade:

  #!/bin/sh
   #
  # Event handler script for upgrade server
  #
  #
 case "$1" in
OK)
 ;;
  WARNING)
  ;;
  UNKNOWN)
   ;;
   CRITICAL)
  case "$2" in
  case "$3" in
    # Wait until the check has been tried 3 times before restarting the web server.
    # If the check fails on the 4th time (after we restart the web server), the state
    # type will turn to "hard" and contacts will be notified of the problem.
    # Hopefully this will restart the web server successfully, so the 4th check will
    # result in a "soft" recovery. If that happens no one gets notified because we
    # fixed the problem!
    3)
      echo -n "Mise à jour ...."
    #lancement de la commande 
     /usr/bin/aptitude -y full-upgrade
      ;;
    esac
    ;;

  HARD)
      echo -n "Mise à jour ...."
    #lancement de la commande 
     /usr/bin/aptitude -y full-upgrade
    ;;
  esac
  ;;
      esac
      exit 0

and services.cfg:

  ## In this directory you can put all your specific service
   # definitions
   define service{
    use                             generic-service
    host_name                       router
     service_description             APT
     check_command                   check_apt!
     }
   define service{
   host_name    router
   service_description   APT
     max_check_attempts    4
     event_handler    upgrade_server
      }

Thanks in advance

我认为你在定义服务方式上是错误的。
您需要定义APT服务:
define service{ use generic-service host_name router service_description APT check_command check_apt! max_check_attempts 4 event_handler upgrade_server }
你不应该把它们分开。
我试过了,效果很好。

相关内容

  • 没有找到相关文章