서버 통합 · 2 min read · Oct 18, 2025
Nagios 3.x.x/Icinga 1.x.x 서버 통합을 위한 SMS 알림 FoxBox 장치를 통한 Debian Squeeze
Nagios 3.x.x/Icinga 1.x.x 서버 통합을 위한 SMS 알림 FoxBox 장치를 통한 Debian Squeeze
이 튜토리얼은 표준 Nagios(또는 Icinga) 모니터링 서버를 SMS 알림 외부 장치인 FoxBox( www.smsfoxbox.it)와 통합하는 방법을 설명합니다.
1 사전 참고사항
제조업체에 따르면 FoxBox는 하드웨어 사양이 다른 두 가지 유사한 버전(G25 및 LX800)으로 제공됩니다. 이 가이드에서는 SMS 게이트웨이 LX800을 참조할 것입니다(우리는 성능이 더 높고 CompactFlash 저장소가 있기 때문에 이 모델을 구입했습니다). 다른 버전에도 문제없이 확장할 수 있을 것이라고 확신합니다.
우리 서버는 Debian Squeeze에서 Nagios Core 3.5.0(1.4.16 Nagios 플러그인 포함)를 실행합니다. 아마도 다른 배포판에서는 경로가 변경될 수 있지만, 논리는 거의 동일합니다.
2 FoxBox 측 설치
이 장치는 이러한 종류의 통신 작업을 위해 설계되었으므로, 여기서는 다음과 같은 작업만 수행하면 됩니다:
- 모니터링 서버에서 접근 가능한 유효한 IP 주소 제공;
- SMS를 전송하기 위해 테스트된 완전 작동하는 SIM 카드 삽입.
3 서버 측 설치
우선 이 스크립트를 /usr/lib/nagios/plugins/ 폴더에 배치해야 합니다:
#!/usr/bin/perl
use LWP::UserAgent;
use Getopt::Long;
use strict;
use warnings;
use constant OK => 0;
use constant WARNING => 1;
use constant CRITICAL => 2;
use constant UNKNOWN => 3;
use constant SEND_PAGE => "/source/send_sms.php";
my($host);
my($username);
my($password);
my($number);
my($message);
sub usage() {
print("Usage: send_sms -h|--host -u|--user --pw|--pass
-n|--number
-m|--message \n\n");
print(" - SMS FoxBox의 IP 주소 또는 호스트 이름\n");
print(" - SMS FoxBox 관리자 이름\n");
print(" - SMS FoxBox 관리자 비밀번호\n");
print(" - SMS가 전송될 전화번호\n");
print(" - 전송할 메시지\n");
}
sub send_sms {
my($host, $user, $pass, $phonenum, $text) = @_;
my($ua);
my($html_page);
my($response);
my($status_code);
$ua = LWP::UserAgent->new;
$ua->timeout(10);
$response = $ua->post("http://$host" . SEND_PAGE,
[
"username" => $user,
"pwd" => $pass,
"from" => 'Nagios',
"nphone" => $phonenum,
"testo" => $text,
"nc" => "http://$host" . SEND_PAGE
]);
if(!$response->is_success) {
print("ERROR: " . $response->status_line . "\n");
$status_code = UNKNOWN;
}
$html_page = $response->content;
if($html_page =~ /p class="(\w+)"/g) {
if($1 eq "confneg") {
print("ERROR: SMS를 전송할 수 없습니다.\n");
$status_code = UNKNOWN;
}
else {
$status_code = OK;
}
}
else {
print("ERROR: 알 수 없는 페이지 출력\n");
$status_code = UNKNOWN;
}
return $status_code;
}
undef $host;
undef $username;
undef $password;
undef $number;
undef $message;
GetOptions( 'host|H=s' => \$host,
'user|u=s' => \$username,
'pass|pw=s' => \$password,
'number|n=s' => \$number,
'message|m=s' => \$message);
if(!defined $host || !defined $username || !defined $password || !defined $number || !defined $message) {
usage();
exit(UNKNOWN);
}
$message =~ s/\\n/\n/g;
my($ret_status);
$ret_status = send_sms($host, $username, $password, $number, $message);
exit($ret_status);
이 파일에 대한 권한을 적절히 설정하여 Nagios 사용자가 이를 실행할 수 있도록 하는 것도 중요합니다.
이제 우리는 기존 이메일 대신 SMS 채널에서 작동하는 새로운 알림 명령을 추가해야 합니다. 이를 위해 /etc/nagios3/commands.cfg 파일에 다음 줄을 추가해야 합니다:
# 'notify-host-by-foxbox' 명령 정의
define command{
command_name notify-host-by-foxbox
command_line /usr/lib/nagios/plugins/sendSMS.sh -h "127.0.0.1" -u "nagiosadmin" -pw "nagios" -n "$CONTACTPAGER$" -m "호스트 경고: $HOSTNAME$ \n호스트 상태: $HOSTSTATE$ \n날짜/시간: $LONGDATETIME$"
}
# 'notify-service-by-foxbox' 명령 정의
define command{
command_name notify-service-by-foxbox
command_line /usr/lib/nagios/plugins/sendSMS.sh -h "127.0.0.1" -u "nagiosadmin" -pw "nagios" -n "$CONTACTPAGER$" -m "서비스 경고: $HOSTALIAS$/$SERVICEDESC$ \n서비스 상태: $SERVICESTATE$ \n날짜/시간: $LONGDATETIME$"
}
보시다시피, 우리는 연락처에 대한 새로운 정보가 필요합니다: 전화번호입니다. 따라서 /etc/nagios3/conf.d/contacts_nagios2.cfg 파일에서 “pager”로 정의해야 합니다.
또한 서비스/호스트 알림 명령을 설정합니다. 기본적으로 이들은 이메일 채널을 사용하고 있으며, 우리는 새로운 알림 명령으로 경고하고 싶으므로 “service_notification_commands” 및 “host_notification_commands” 매개변수도 편집해야 합니다:
define contact{
contact_name test-contact
use generic-contact
alias tester
email yourname@domain
host_notification_commands notify-host-by-foxbox
service_notification_commands notify-service-by-foxbox
pager 12453683421
}
물론, 구성을 마친 후에는 Nagios 서비스를 재시작하여 그 효과를 확인해야 합니다.
모든 것이 정상인지 확인하기 위해, 아마도 다음과 같이 사전 점검을 실행할 수 있습니다:
nagios3 -v /etc/nagios3/nagios.cfg제가 보기에 이 아키텍처는 또한 FoxBox의 여러 버전에서 구현되어 있으며, 올인원 알림 솔루션(EasyG2 G25 및 Monitoring LX800)을 제공합니다.
(참고: www.smsfoxbox.it)
새 게시물을 받은 편지함에서 받기
스팸은 없습니다. 언제든지 구독 해지 가능합니다.