#!/usr/bin/perl

# Copyright (C) 2003 NEC Corporation
# All Rights Reserved.

# RCS: $Id: chksvc,v 1.1 2006/12/22 05:33:58 shodai Exp $

require "/opt/nec/wbmc/lib/wbmc.pl";
require "/opt/nec/wbmc/adm/service/97chksvc/chksvc.pl";


$def = "def";
$sel = "sel";
$call = 1;

$success_notice  = 1;       # サービス正常通知
$failure_notice  = 2;       # サービス異常通知

# サービス監視間隔、正常時メール送信有無情報取得
($interval, $check_mail) = &get_interval_chkmail(1);

# サービスチェック(デフォルト)
@err_def = &chk_svc($def, $call);

# サービスチェック(選択)
@err_sel = &chk_svc($sel, $call);

@err_services = split (' ', ((join (' ', @err_def)) . " " .  (join (' ', @err_sel))));
$err_num = $#err_services + 1;

# シスログ記録、管理者へメール送信
if ($err_num < 0) {     # 不正ステータス
    print "サービス監視結果が不正です。\n";
    exit(1);
} elsif ($err_num == 0) {     # サービス正常
    if ($check_mail == 0) {
        ;    # 何もしない
    } elsif ($check_mail == 1) {
        # シスログ記録(正常)
        &write_syslog($success_notice);

        # 管理者へメール送信(正常)
        &send_mail($success_notice);

    } else {
        print "正常時もメール送信設定が不正です。\n";
        exit(1);
    }
} else {     # サービス異常
    # シスログ記録(異常)
    &write_syslog($failure_notice, @err_services);

    # 管理者へメール送信(異常)
    &send_mail($failure_notice, @err_services);

}
