#!/opt/VRTSnc/bin/perl -w # Copyright c 2003 Southern Company Services, Inc. # All rights reserved # This program is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. # use strict; use IO::Socket; use Carp; use Time::localtime; my $paserver_host = shift || 'gaxgpov4'; my $inform_number = shift || 100000; my $num_attrs = shift || 0; my @attributes = @ARGV; my $debug = 1; my ($paserver_port, $protocol) = ('32509', 'tcp'); my $nc_server_host_name = "gaxgpov4"; my @varbinds = (); my $varbind17 = ""; my $data = ""; my $header1 = ""; my $data1 = ""; my $header2 = ""; my $data2 = ""; my $data_prefix1 = ""; my $data_prefix2 = ""; my $payload = ""; my $payload1 = ""; my $payloadlen1 = 0; my $payload2 = ""; my $payloadlen2 = 0; my $nulls = "00000000"; my $i = 0; my $result = 0; my $strlen = 0; my ($sec, $min, $hr, $day, $mon, $yr) = (); $varbinds[0] = "NerveCenter Server: $nc_server_host_name"; $varbinds[1] = ""; # Date and time stamp $varbinds[2] = ""; # Inform number $varbinds[3] = "GAXGPOV4"; # Source node name. $varbinds[4] = "148.199.226.39"; # Source node IP address. $varbinds[5] = "U1d4MLDB8"; # Node RO community string. $varbinds[6] = "U1d4MLDB8"; # Node RW community string. $varbinds[7] = "SCS-Nervectr"; # Node property group. $varbinds[8] = "SCS-InformOmatic"; # Alarm name. $varbinds[9] = "informOmatic"; # Alarm property. $varbinds[10] = "Send Inform"; # Source state name. $varbinds[11] = "Inform"; # Source state severity. $varbinds[12] = "Send Inform"; # Destination state name. $varbinds[13] = "Inform"; # Destination state severity. $varbinds[14] = "informOmatic"; # Trigger name. $varbinds[15] = "NO_OBJECT"; # Base object. $varbinds[16] = "0"; # Instance. $varbinds[17] = "-2"; # Trap generic number. $varbinds[18] = "-2"; # Trap specific number. $varbinds[19] = "01000000010000"; # Trap entity ID. $varbinds[20] = $num_attrs; # Num attributes. $varbinds[21] = "3245"; # Alarm instance ID. # # Create data to send. # $strlen = length($varbinds[0]) + 1; $varbinds[0] =~ s/(.)/sprintf("%2.2x", ord($1))/eg; # Convert to hex $varbinds[0] = sprintf "%2.2x%6.6s%2.2x%s%8.8s", $strlen, $nulls, $strlen, $varbinds[0], $nulls; print "varbind 0 :$varbinds[0]\n" if $debug; $sec = localtime->sec; $min = localtime->min; $hr = localtime->hour; $day = localtime->mday; $mon = localtime->mon + 1; $yr = localtime->year + 1900; $varbinds[1] = sprintf "%2.2d%2.2d%4.4d%2.2d%2.2d%2.2d", $mon, $day, $yr, $hr, $min, $sec; print "varbind 1 :$varbinds[1]\n" if $debug; $varbinds[1] =~ s/(.)/sprintf("%2.2x", ord($1))/eg; # Convert to hex $varbinds[1] = sprintf "0f%s%4.4s", $varbinds[1], $nulls; print "varbind 1 :$varbinds[1]\n" if $debug; $varbinds[2] = sprintf "%6.6x%2.2s", $inform_number, $nulls; print "varbind 2 :$varbinds[2]\n" if $debug; for ($i = 3; $i <= 18; $i++) { print "varbind $i :$varbinds[$i]\n" if $debug; $strlen = length($varbinds[$i]) + 1; $varbinds[$i] =~ s/(.)/sprintf("%2.2x", ord($1))/eg; # convert to hex print "varbind $i :$varbinds[$i]\n" if $debug; $varbinds[$i] = sprintf "%2.2x%6.6s%2.2x%s%4.4s", $strlen, $nulls, $strlen, $varbinds[$i], $nulls; print "varbind $i :$varbinds[$i]\n" if $debug; } if ($num_attrs) { print "varbind 20 :$varbinds[20]\n" if $debug; $varbinds[20] = sprintf "%2.2x%2.2s", $varbinds[20], $nulls; print "varbind 20 :$varbinds[20]\n" if $debug; for ($i = 0; $i <= (@attributes - 1); $i++) { $attributes[$i] = "Attribute ".$attributes[$i]; print "attribute $i:$attributes[$i]\n" if $debug; $strlen = length($attributes[$i]) + 1; $attributes[$i] =~ s/(.)/sprintf("%2.2x", ord($1))/eg; # convert to hex $attributes[$i] = sprintf "%2.2x%6.6s%2.2x%s%4.4s", $strlen, $nulls, $strlen, $attributes[$i], $nulls; print "attribute $i:$attributes[$i]\n" if $debug; $varbind17 = $varbind17.$attributes[$i]; } } else { $varbinds[20] = "0000"; print "varbind 20 :$varbinds[20]\n" if $debug; $varbinds[20] = sprintf "%4.4x", $varbinds[20]; $varbind17 = ""; } $strlen = length($varbinds[21]) + 1; $varbinds[21] =~ s/(.)/sprintf("%2.2x", ord($1))/eg; # convert to hex print "varbind 21 :$varbinds[21]\n" if $debug; $varbinds[21] = sprintf "%2.2x%6.6s%2.2x%s%2.2s", $strlen, $nulls, $strlen, $varbinds[21], $nulls; print "varbind 21 :$varbinds[21]\n" if $debug; $data_prefix1 = "03060003000000"; # Trap inform #$data_prefix2 = "0300000001000023940000000000000040000000000000000700"; # Tivoli Inform #$data_prefix2 = "0300000002000023940000000000000040000000000000000700"; # Netcool Inform $data_prefix2 = "0300000003000023940000000000000040000000000000000700"; $data2 = $data_prefix2.$varbinds[0].$varbinds[1].$varbinds[2].$varbinds[3].$varbinds[4].$varbinds[5].$varbinds[6].$varbinds[7].$varbinds[8].$varbinds[9].$varbinds[10].$varbinds[11].$varbinds[12].$varbinds[13].$varbinds[14].$varbinds[15].$varbinds[16].$varbinds[17].$varbinds[18].$varbinds[19].$varbinds[20].$varbind17.$varbinds[21]; $payload2 = pack("H*", $data2); $payloadlen2 = length($payload2); print "Inside payload len:$payloadlen2\n" if $debug; $header2 = sprintf "%s%4.4x%6.6s", $data_prefix1, $payloadlen2, $nulls; print "Inside header:$header2\n" if $debug; $data1 = $header2.$data2; $payload1 = pack("H*", $data1); $payloadlen1 = length($payload1); print "Outside payload len:$payloadlen1\n" if $debug; $header1 = sprintf "%8.8x", $payloadlen1; print "Outside header:$header1\n" if $debug; $data = $header1.$data1; $payload = pack("H*", $data); # # Open the socket connection or die with error message. # my $socket = IO::Socket::INET->new(PeerAddr => $paserver_host, PeerPort => $paserver_port, Proto => $protocol) or croak "Could not connect to $paserver_host:$paserver_port\n"; # # Send data to socket. # $result = $socket->send($payload); $result or carp "Failed to send varbinds to $paserver_host:$paserver_port\n"; # # Close it up. # $result = $socket->close(); $result or carp "Could not close socket $paserver_port on $paserver_host : $@\n"; 1; __END__ =head1 NAME inform.pl - Send Inform to NerveCenter's paserver process =head1 SYNOPSIS use NC::Inform; # Constructors $pop = NC::Inform->new('informhost'); =head1 DESCRIPTION This Perl script implements a client to the NerveCenter platform adapter server (paserver). All forms of informs than can be sent from NerveCenter to paserver can also be sent by this script. Three parameters must be provided to this routine, the inform number, the host on which paserver is running, and the platform to which the inform is being sent. =head1 CHANGE HISTORY Date Who. Comments ------------- ---------------------------------------------------- 20 June 2003 Scott Parker. Created. 24 June 2003 Worked with varbind formatting. 25 June 2003 "Variable-ized" data in inform. =head1 PARAMETERS SENT IN INFORM =item 1 Server ID Consists of string "NerveCenter Server: serverhostname". The NerveCenter variable $NCHostName is used internally to this script to provide the server's hostname. =item 2 Date and timestamp 14 character string formatted as MMDDYYYYHHMMSS. Single digit months, days, hours, etc. must have leading 0. This script retrieves the current date and time and formats it appropriately. =item 3 Inform number Inform number encoded as 3 byte hex. The inform number is passed to this script as an integer. =item 4 Source node hostname String consisting of source node hostname. The NerveCenter variable $NodeName is used internally to this script. =item 5 Source node IP address String consisting of source node IP address. The NerveCenter variable $NodeAddress is used internally to this script. =item 6 Source node read only community String consisting of source node read only community string. The NerveCenter variable $ReadCommunity is used internally to this script. =item 7 Source node read-write community String consisting of source node read-write community string. The NerveCenter variable $WriteCommunity is used internally to this script. =item 8 Node property group String consisting of node property group. The NerveCenter variable $NodePropertyGrp is used internally to this script. =item 9 Alarm name String consisting of alarm name. The NerveCenter variable $AlarmName is used internally to this script. =item 10 Alarm property String consisting of alarm name. The NerveCenter variable $AlarmProperty is used internally to this script. =item 11 Originating state name String consisting of name of originating state of transition. The NerveCenter variable $OrigState is used internally to this script. =item 12 Originating state severity String consisting of severity of originating state of transition. The NerveCenter variable $OrigStateSev is used internally to this script. =item 13 Destination state name String consisting of name of destination state of transition. The NerveCenter variable $DestState is used internally to this script. =item 14 Destination state severity String consisting of severity of destination state of transition. The NerveCenter variable $DestStateSev is used internally to this script. =item 15 Trigger name String consisting of the name of the trigger that caused transition. The NerveCenter variable $TriggerName is used internally to this script. =item 16 Trigger base object name String consisting of the name of the trigger base object. The NerveCenter variable $TriggerBaseObject is used internally to this script. =item 17 Trigger instance String consisting of the trigger instance. The NerveCenter variable $TriggerInstance is used internally to this script. =item 18 Trap generic number String consisting of the trap generic number. The trap generic number defaults to "-2". =item 19 Trap specific number String consisting of the trap specific number. The trap specific number defaults to "-2". =item 20 Trap entity ID String consisting of the trap entity (??) ID. =item 21 Number of inform attributes One byte count of number of attributes (might also be called varbinds) included in the inform. =item 22 Alarm instance ID String consisting of the instance ID of the NerveCenter alarm. The NerveCenter variable $AlarmInstanceID is used in the NerveCenter version of this script. =head1 AUTHOR Scott W. Parker =head1 COPYRIGHT Copyright (c) 2003 Southern Company Services, Inc. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut