33 |
|
$fqdn |
34 |
|
$pidfile |
35 |
|
$retry_wait |
36 |
< |
@statgrab |
36 |
> |
@data |
37 |
|
); |
38 |
|
|
39 |
|
if (@ARGV != 2) { |
47 |
|
$retry_wait = 60; |
48 |
|
|
49 |
|
# write our PID to a file |
50 |
< |
$pidfile = "/var/tmp/ihost.pid"; |
50 |
> |
# use home dir by default |
51 |
> |
$pidfile = $ENV{"HOME"}; |
52 |
> |
# or drop it in /var/tmp if we can't find HOME |
53 |
> |
$pidfile = "/var/tmp" if not defined $pidfile; |
54 |
> |
$pidfile .= "/.ihost.pid"; |
55 |
|
&write_pid(); |
56 |
|
|
57 |
|
&tcp_configure(); |
261 |
|
#----------------------------------------------------------------------- |
262 |
|
sub send_udp_packet() { |
263 |
|
|
264 |
< |
@statgrab = `./statgrab.pl`; |
264 |
> |
my($plugins_dir) = "plugins"; |
265 |
|
|
266 |
+ |
opendir PLUGINS, $plugins_dir; |
267 |
+ |
my(@plugins) = readdir PLUGINS; |
268 |
+ |
foreach my $plugin (@plugins) { |
269 |
+ |
push @data, `$plugins_dir/$plugin` if -x "$plugins_dir/$plugin" && -f "$plugins_dir/$plugin"; |
270 |
+ |
} |
271 |
+ |
|
272 |
|
# get some extra data |
273 |
|
my($date) = time; |
274 |
|
my($ip); |
275 |
|
$ip = inet_ntoa(scalar(gethostbyname(hostname())) || 'localhost') or $ip = 'localhost'; |
276 |
|
|
277 |
|
# add some extra data to the array |
278 |
< |
push(@statgrab, "packet.attributes.seq_no=$seq_no"); |
279 |
< |
push(@statgrab, "packet.attributes.machine_name=$fqdn"); |
280 |
< |
push(@statgrab, "packet.attributes.date=$date"); |
281 |
< |
push(@statgrab, "packet.attributes.type=data"); |
282 |
< |
push(@statgrab, "packet.attributes.ip=$ip"); |
278 |
> |
push(@data, "packet.attributes.seq_no=$seq_no"); |
279 |
> |
push(@data, "packet.attributes.machine_name=$fqdn"); |
280 |
> |
push(@data, "packet.attributes.date=$date"); |
281 |
> |
push(@data, "packet.attributes.type=data"); |
282 |
> |
push(@data, "packet.attributes.ip=$ip"); |
283 |
|
|
284 |
+ |
# sort the data |
285 |
+ |
@data = sort(@data); |
286 |
+ |
|
287 |
|
# turn the array into some nice XML |
288 |
|
my($xml) = &make_xml("", ""); |
289 |
|
|
401 |
|
|
402 |
|
#----------------------------------------------------------------------- |
403 |
|
# make_xml |
404 |
< |
# Turns an array of statgrab data into an XML string. |
404 |
> |
# Turns an array of plugins data into an XML string. |
405 |
|
#----------------------------------------------------------------------- |
406 |
|
sub make_xml() { |
407 |
|
my($curlevel, $curline) = @_; |
408 |
|
my($xmltemp) = ""; my($curtag) = ""; my($attributes) = ""; |
409 |
< |
while(true) { |
410 |
< |
$curline = shift(@statgrab) if $curline eq ""; chomp $curline; |
409 |
> |
while(1) { |
410 |
> |
$curline = shift(@data) if $curline eq ""; chomp $curline; |
411 |
|
if($curline =~ /^$curlevel([^\.\s]+\.)/) { |
412 |
|
$curtag=$1; |
413 |
|
} |
420 |
|
else { |
421 |
|
$xmltemp .= &make_xml("$curlevel$curtag", $curline); |
422 |
|
} |
423 |
< |
my($nextline) = $statgrab[0]; chomp $nextline if defined $nextline; |
423 |
> |
my($nextline) = $data[0]; chomp $nextline if defined $nextline; |
424 |
|
$curtag =~ s/(.*)\./$1/; |
425 |
< |
if(defined $nextline && $nextline =~ /^$curlevel$curtag\./) { |
425 |
> |
if((defined $nextline) && ($nextline =~ /^$curlevel$curtag\./)) { |
426 |
|
$curline = ""; |
427 |
|
} |
428 |
|
else { |