LoginSignup
3

More than 5 years have passed since last update.

SAPシステムをZabbixで監視する。(Linux版)

Posted at

はじめに

前回投稿から半年がたってしまいました。。。反省。

Zabbix を利用してSAPシステムの稼働監視を行う際に簡単なシェルスクリプトを作成し、 監視できるようにした話です。

本稿でのSAPは「SAP Netweaver ABAP/JAVA」を示すこととします。

概要

Zabbix は UserParameterを利用して任意のOSコマンド、シェルスクリプト標準出力を監視できます。そこで、SAPの稼働状況を示す値を標準出力に出力するシェルスクリプトを作成し監視します。

「SAPの稼働状況」とは

本稿の中でSAPの稼働状況はsapcontrolコマンドのGetProcessList関数で出力されるdispstatusのことと定義します。
以下の表はdispstatusに出力される値とその値が示す稼働状態、スクリプトの出力値です。

dispstatus 状態 スクリプトの出力値
GREEN 稼働中 3
YELLOW 起動中 2
RED 障害 1
GRAY 停止中 0

実装

前提

  • Zabbix Agentはrootユーザで動作させること
  • sapstartsrv プロセスは別途プロセス監視すること (sapstartsrvが停止しているとsapcontrolコマンドで稼働状況を取得できなくなるため)

シェルスクリプトの流れ

以下の流れで処理します。

  1. saphostctrlコマンドのListInstances関数でサーバにインストールされているSAPインスタンスのインスタンス番号を取得する。
  2. 取得したインスタンス番号ごとにsapcontrolコマンドのGetProcessList関数でSAPインスタンスの稼働状況を取得する。
  3. GREEN > YELLOW > RED > GRAY の順でもっとも下位の状態をホスト全体のSAP稼働状況として標準出力に出力する。

監視シェルスクリプトソースコード

check_sap_status.sh
#!/bin/bash
readonly SAPHOSTCTRL="/usr/sap/hostctrl/exe/saphostctrl"
readonly SAPCONTROL="/usr/sap/hostctrl/exe/sapcontrol"

readonly CNS_INITIAL=4
readonly CNS_GREEN=3
readonly CNS_YELLOW=2
readonly CNS_RED=1
readonly CNS_GRAY=0
### Functions ####
function check_status() {
  local sys_status="${CNS_INITIAL}"
    for nr in `"${SAPHOSTCTRL}" -function ListInstances | awk '{print $6}'`
    do
      sys_status="$(check_instance_status "${sys_status}" "${nr}")"
    done
    echo "${sys_status}"
}
function check_instance_status() {
  local status="${1}"
  local nr="${2}"
  while read dispstatus
  do
    case "${dispstatus}" in
      GREEN)  test "${status}" -ge "${CNS_GREEN}" && status="${CNS_GREEN}"
              ;;
      YELLOW) test "${status}" -ge "${CNS_YELLOW}" && status="${CNS_YELLOW}"
              ;;
      RED)    test "${status}" -ge "${CNS_RED}" && status="${CNS_RED}"
              ;;
      GRAY)   test "${status}" -ge "${CNS_GRAY}" && status="${CNS_GRAY}"
              ;;
    esac
  done < <("${SAPCONTROL}" -format script -nr "${nr}" -function GetProcessList | grep dispstatus|awk '{print $3}')
  echo "${status}"
}

### Main Proc ####
check_status

UserParameter 設定

/etc/zabbix/zabbix_agentd.d/userparameter_sap.conf
UserParameter=sap.status[*],/etc/zabbix/plugin/sap/check_sap_status.sh

アイテム設定(Zabbix Server)

2018-08-22 22_33_55.png

トリガー設定(Zabbix Server)

GREENを表す 3以外を障害と判断するように条件式を設定

2018-08-22 22_40_16.png

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3