-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnmp_readfile.pl
More file actions
executable file
·55 lines (41 loc) · 898 Bytes
/
snmp_readfile.pl
File metadata and controls
executable file
·55 lines (41 loc) · 898 Bytes
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
#!/usr/bin/perl
use SNMP::Persist qw(&define_oid &start_persister &define_subtree);
use strict;
use warnings;
use Data::Dumper;
my $oid = $ARGV[0];
my $file = $ARGV[1];
undef @ARGV;
#define base oid to host the subtree
define_oid($oid);
#start the thread serving answers
start_persister();
#loop forever to update the values
# Open file ....
my $result;
while (1)
{
if (!defined($file))
{
$result = "File does not exist";
} else {
if (-s $file )
{
$result = "";
open (IN, "<$file") or $result = "$!";
while (<IN>)
{
chomp $_;
$result = $result.$_;
}
close IN;
}
}
my %subtree;
$subtree{"1." . 1}=["INTEGER",$result] if ($result =~ /^\d+$/);
$subtree{"1." . 1}=["STRING",$result] if ($result !~ /^\d+$/);
$subtree{"2." . 1}=["STRING","Average Queue Time"];
#new values have arrived - notify the subtree controller
define_subtree(\%subtree);
sleep 60;
}