$monitordb{ $ref->{address}->[$i]->{ip} } = $r;
$monitordb{ $ref->{address}->[$i]->{ip} } = [$r , "feld2" , "feld3" ];
Invalid value for shared scalar at
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
#!/usr/bin/perl
use strict;
use warnings;
use Carp;
use English '-no_match_vars';
use feature qw/switch/;
use Hgldns;
use Net::DNS::Nameserver;
use Hgltools::Hglreadfile;
use XML::Simple;
use Data::Dumper;
use threads;
use threads::shared;
use Hglmonitor;
my $monitordb :shared;
share ($monitordb);
my $xs = XML::Simple->new();
my $xmlconfig = \$xs->XMLin('./serverdb.xml');
my $ns = new Net::DNS::Nameserver(
LocalAddr => '127.0.0.1',
LocalPort => '53',
ReplyHandler => \&call_resolver,
Verbose => 1
) or croak "couldn't create nameserver object $ERRNO\n";
my $hgldns = Hgldns->new();
sub call_hostchecker {
my $ref = shift;
my $m = Hglmonitor->new();
while (1) {
my $i=0;
print "start hostcheck \n";
while ( $ref->{address}->[$i] ) {
my $r;
if ( $ref->{address}->[$i]->{check}->{type} eq 'http' ) {
$r = $m->monitor({checktype=>$ref->{address}->[$i]->{check}->{type},
ip=>$ref->{address}->[$i]->{ip},
port=>$ref->{address}->[$i]->{port},
response=>$ref->{address}->[$i]->{check}->{response},
url=>$ref->{address}->[$i]->{check}->{url},});
} else {
$r = $m->monitor({checktype=>$ref->{address}->[$i]->{check}->{type},ip=>$ref->{address}->[$i]->{ip},});
}
$ref->{address}->[$i]->{status} = $r;
my $cl_ref = shared_clone ({obj => $ref});
bless $cl_ref,'Status';
$monitordb = $cl_ref;
$i++;
}
sleep $ref->{interval};
}
return ;
}
sub call_resolver {
my ($qname, $qclass, $qtype, $peerhost,$query,$conn) = @_;
print Dumper $monitordb;
if ( $qtype ne 'A' ) {
# #my @resolver = $hgldns->resolv({type=>$qtype,name=>$qname,class=>$qclass});
$hgldns->resolv({type=>$qtype,name=>$qname,class=>$qclass});
} else {
# $hgldns->resolv({type=>$qtype,name=>$qname,class=>$qclass});
$hgldns->prox_engine({type=>$qtype,name=>$qname,class=>$qclass,monitordb=>\$monitordb,});
}
}
#$ns->loop_once(60);
#call_hostchecker(${$xmlconfig});
my $monitor = threads->create(\&call_hostchecker,${$xmlconfig}) ;
$ns->main_loop;