-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackend.pl
107 lines (76 loc) · 2.53 KB
/
backend.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/perl -w
use DBI;
use Net::SNMP;
use 5.010001;
use Mail::Sender;
$rttStatus= "";
$sstStatus= "";
$drsStatus= "";
%conf=do "db.conf";
$connect=DBI->connect("DBI:mysql:".$conf{database}.";".$conf{host}.";".$conf{port},$conf{username},$conf{password});
$query_select = "SELECT * FROM `notifications`";
$query = $connect->prepare($query_select);
$query->execute();
@row=$query->fetchrow_array();
$thresholdRTT=$row[1];
$thresholdSST=$row[3];
$thresholdDRS=$row[5];
$res = "SELECT * FROM Average";
$query1 = $connect->prepare($res);
$query1->execute();
@row1=$query1->fetchrow_array();
$avgRTT = $row1[0];
$avgSST = $row1[1];
$avgDRS = $row1[2];
if($avgRTT>$thresholdRTT)
{
$rtt="1"; $rttStatus= " RTT threshold exceeded " ;
}
if($avgSST>$thresholdSST)
{
$sst="1"; $sstStatus= " SST threshold exceeded " ;
}
if($avgDRS>$thresholdDRS)
{
$drs="1"; $drsStatus= " Data Rate threshold exceeded " ;
}
if ($rtt == "1" || $sst == "1" || $drs=="1")
{
$query_select = "SELECT * FROM `notifications`";
$query = $connect->prepare($query_select);
$query->execute();
@row=$query->fetchrow_array();
$email=$row[7];
print "this is $email.\n";
my $sender = new Mail::Sender {
auth => 'LOGIN',
authid => '[email protected]',
authpwd => 'pXpbPB_f',
smtp => 'smtp.office365.com',
port => 587,
from => '[email protected]',
to => $email,
subject => 'WARNING!! WARNING!!',
msg => 'THRESHOLD EXCEEDED',
};
#my $result = $sender->MailFile({
my $result = $sender->MailMsg({
msg => $sender->{msg},
#file => $sender->{file},
});
print "$sender->{error_msg}\n>>>End.\n";
#--------------------------------------------------------------------------------------------
print "hostname $row[8] Community $row[11] Port $row[10]";
$sessionA = Net::SNMP->session(Hostname => $row[8],Community => $row[11],Port => $row[10]);
$error_message = $sessionA->error();
print "The error message is $error_message\n";
$basha = "$row[9]";
$trap = "$rttStatus $sstStatus $drsStatus";
@oids = ($basha,OCTET_STRING, $trap);
$resultA = $sessionA->trap(-varbindlist => \@oids);
$sessionA->close;
#-----------------------------------------------------------------------------------------------
print "End of the session";
}
system ("rm -rf test_in.txt test_out.txt tcp.txt");
system ("perl head.pl");