Hi, I made a program that works with my HP Openview to send a list of events for the last 48 hours. My program runs a system command to list the events in a file. Then my program runs a system command (findstr) and writes to another file containing the lines I want to send. It then reads the results and emails the file contents. This works, however I got the bug and want to improve the results. I included below a sample of the file contents and my program.
I’d like to improve it by removing the extra information and deliver only parts of each line.
For example the first two lines,
1152897223 4 Fri 07 14 13:13:43 2006 Node1 M NW IC-3 Node Up Node1 Se0;1 17.1.0.58916864 4026
1152928755 4 Fri 07 14 21:59:15 2006 SomeBank_Fidelity M NW IC-3 Node Down SomeBank_Fidelity Se1/0.2;3 17.1.0.58916865 77020
I really only want to see
Fri 07 14 13:13:43 2006 Node1 NW IC-3 Node Up
Fri 07 14 21:59:15 2006 SomeBank_Fidelity NW IC-3 Node Down
The words on the lines are separated by spaces and one by a tab. How can I achieve this? I’m a relative novice. My programs for the most part are a patchwork other people’s programs.
Below I included my program and a sample of the results the find string windows command.
The file:
1152897223 4 Fri 07 14 13:13:43 2006 Node1 M NW IC-3 Node Up Node1 Se0;1 17.1.0.58916864 4026
1152928755 4 Fri 07 14 21:59:15 2006 SomeBank_Fidelity M NW IC-3 Node Down SomeBank_Fidelity Se1/0.2;3 17.1.0.58916865 77020
1152929469 4 Fri 07 14 22:11:09 2006 Another_NodeM NW IC-3 Node Up Another_Node Se0/0;1 17.1.0.58916864 34518
1152930212 4 Fri 07 14 22:23:32 2006 DMZ_1_ROUTER M NW IC-1 Node Up DMZ_1_ROUTER Se5/0.21;1 17.1.0.58916864 2019
1152930349 4 Fri 07 14 22:25:49 2006 SomeBank_Fidelity M NW IC-3 Node Up SomeBank_Fidelity Se1/0.2;1 17.1.0.58916864 77020
1152930350 4 Fri 07 14 22:25:50 2006 DMZ_2_ROUTER M NW IC-1 Node Up DMZ_2_ROUTER Se0/0.9;1 17.1.0.58916864 2542
My program/script
#this worked using command C:\>c:\\ovscripts\\perl "C:\\ovscripts\\scripts\\NWALARMem.pl"
BEGIN {
if ($^O eq "MSWin32") {
@INC = (
# Set the path to your Perl Scripting directory if different
'c:\ovscripts\perl5\site_perl\5.005',
'c:\ovscripts\perl5\site_perl\5.005\MSWin32-x86');
}
}
system ("ovdumpevents -l 2880 > RecentAlarms.txt");
system ('findstr /c:"NW IC" RecentAlarms.txt >fndnw.txt');
open (ALARMS, 'fndnw.txt');
my @data = ("\n", <ALARMS>);
use Net::SMTP;
use strict;
my $MAILHOST = 'mail.smtpgate.soandso.net';
my $smtp = Net::SMTP->new($MAILHOST, Timeout => 10) or die "Unable to connect to mail host : $MAILHOST - $!\n";
my @receipiants = ('Ru55ell@WhereIwork.com','someone.else@WhereIwork');
my $FROM = 'HP.Openview@WhereIwork ';
foreach my $receipiants (@receipiants)
{
$smtp->mail("$receipiants");
$smtp->to("$receipiants");
$smtp->data();
$smtp->datasend("From: $FROM\n");
$smtp->datasend("To: $receipiants\n");
$smtp->datasend("Subject: NW Activity for last 48 hrs");
$smtp->datasend("\n@data");
$smtp->datasend();
$smtp->dataend();
}
$smtp->quit;
I’d like to improve it by removing the extra information and deliver only parts of each line.
For example the first two lines,
1152897223 4 Fri 07 14 13:13:43 2006 Node1 M NW IC-3 Node Up Node1 Se0;1 17.1.0.58916864 4026
1152928755 4 Fri 07 14 21:59:15 2006 SomeBank_Fidelity M NW IC-3 Node Down SomeBank_Fidelity Se1/0.2;3 17.1.0.58916865 77020
I really only want to see
Fri 07 14 13:13:43 2006 Node1 NW IC-3 Node Up
Fri 07 14 21:59:15 2006 SomeBank_Fidelity NW IC-3 Node Down
The words on the lines are separated by spaces and one by a tab. How can I achieve this? I’m a relative novice. My programs for the most part are a patchwork other people’s programs.
Below I included my program and a sample of the results the find string windows command.
The file:
1152897223 4 Fri 07 14 13:13:43 2006 Node1 M NW IC-3 Node Up Node1 Se0;1 17.1.0.58916864 4026
1152928755 4 Fri 07 14 21:59:15 2006 SomeBank_Fidelity M NW IC-3 Node Down SomeBank_Fidelity Se1/0.2;3 17.1.0.58916865 77020
1152929469 4 Fri 07 14 22:11:09 2006 Another_NodeM NW IC-3 Node Up Another_Node Se0/0;1 17.1.0.58916864 34518
1152930212 4 Fri 07 14 22:23:32 2006 DMZ_1_ROUTER M NW IC-1 Node Up DMZ_1_ROUTER Se5/0.21;1 17.1.0.58916864 2019
1152930349 4 Fri 07 14 22:25:49 2006 SomeBank_Fidelity M NW IC-3 Node Up SomeBank_Fidelity Se1/0.2;1 17.1.0.58916864 77020
1152930350 4 Fri 07 14 22:25:50 2006 DMZ_2_ROUTER M NW IC-1 Node Up DMZ_2_ROUTER Se0/0.9;1 17.1.0.58916864 2542
My program/script
#this worked using command C:\>c:\\ovscripts\\perl "C:\\ovscripts\\scripts\\NWALARMem.pl"
BEGIN {
if ($^O eq "MSWin32") {
@INC = (
# Set the path to your Perl Scripting directory if different
'c:\ovscripts\perl5\site_perl\5.005',
'c:\ovscripts\perl5\site_perl\5.005\MSWin32-x86');
}
}
system ("ovdumpevents -l 2880 > RecentAlarms.txt");
system ('findstr /c:"NW IC" RecentAlarms.txt >fndnw.txt');
open (ALARMS, 'fndnw.txt');
my @data = ("\n", <ALARMS>);
use Net::SMTP;
use strict;
my $MAILHOST = 'mail.smtpgate.soandso.net';
my $smtp = Net::SMTP->new($MAILHOST, Timeout => 10) or die "Unable to connect to mail host : $MAILHOST - $!\n";
my @receipiants = ('Ru55ell@WhereIwork.com','someone.else@WhereIwork');
my $FROM = 'HP.Openview@WhereIwork ';
foreach my $receipiants (@receipiants)
{
$smtp->mail("$receipiants");
$smtp->to("$receipiants");
$smtp->data();
$smtp->datasend("From: $FROM\n");
$smtp->datasend("To: $receipiants\n");
$smtp->datasend("Subject: NW Activity for last 48 hrs");
$smtp->datasend("\n@data");
$smtp->datasend();
$smtp->dataend();
}
$smtp->quit;