Tuesday, March 11, 2008

Acknowledging/Closing situations from Command Line

ITM does not provide any command line to acknowledge or close situations. However, by using TEMS.pm Perl module, we will be able to acknowledge or close an event. This blog article shows how to do it.

Program Description
Before using this program, make sure that you downloaded the TEMS.pm Perl module. The Perl program listed below uses the module to acknowledge or close situations. The user should provide the name and source (the managed system name) of the situation in command line. The program invokes CT_Acknowledge or CT_Reset method calls to acknowledge or reset the situation.

In the following example, the GBS_NT_Diskspace_Low situation on managed system Primary:VIKING:NT is acknowledged with a message "Auto-acknowledged".

situationack.pl -s GBS_NT_Diskspace_Low -h Primary:VIKING:NT

In the example below, the GBS_NT_Diskspace_Low situation on managed system Primary:VIKING:NT is reset.

situationack.pl -s GBS_NT_Diskspace_Low -h Primary:VIKING:NT -r

Source Code

# include the TEMS SOAP abstraction module
use TEMS;

# include GBS Wrapper module to TEMS
use GBSSoap;
use Getopt::Std;

use strict;

my ($tems, $gbssoap, $situation, @situations, %opt);
my ($situtation, $managedSystem, $ack_message);

getopts("s:h:m:r", \%opt);

usage() unless ($opt{'h'} or $opt{'s'});

$situation = $opt{'s'};
$managedSystem = $opt{'h'};
$ack_message = $opt{'m'} || "Auto-acknowledged";

# initialize new TEMS object, viking is the server name
# default port is 1920, default user id sysadmin, no password.
$tems = TEMS->new("localhost");

$tems->CT_Acknowledge($situation, $managedSystem, $ack_message) unless $opt{'r'};
$tems->CT_Reset($situation, $managedSystem) if $opt{'r'};


sub usage {
'????????? print STDERR << "EOF";
'????????? $0 -h -s [-m message] [-r]

'????????? Acknowledges or closes the given situation on the given hostname.
'????????? By default, the situation will be acknowledged. if -r switch is provided,
'????????? then the situation will be reset (closed).


No comments: