| 33 |
|
$fqdn |
| 34 |
|
$pidfile |
| 35 |
|
$retry_wait |
| 36 |
+ |
$ostype |
| 37 |
|
@data |
| 38 |
|
); |
| 39 |
|
|
| 47 |
|
$seq_no = 1; |
| 48 |
|
$retry_wait = 60; |
| 49 |
|
|
| 50 |
+ |
# work out our platform, if we can. |
| 51 |
+ |
$ostype = `uname -s`; |
| 52 |
+ |
chomp $ostype; |
| 53 |
+ |
$ostype = "unknown" if not defined $ostype; |
| 54 |
+ |
|
| 55 |
|
# write our PID to a file |
| 56 |
< |
$pidfile = "/var/tmp/ihost.pid"; |
| 56 |
> |
# use home dir by default |
| 57 |
> |
#$pidfile = $ENV{"HOME"}; |
| 58 |
> |
# or drop it in /var/tmp if we can't find HOME |
| 59 |
> |
$pidfile = "/var/tmp" if not defined $pidfile; |
| 60 |
> |
$pidfile .= "/.ihost.pid"; |
| 61 |
|
&write_pid(); |
| 62 |
|
|
| 63 |
|
&tcp_configure(); |
| 272 |
|
opendir PLUGINS, $plugins_dir; |
| 273 |
|
my(@plugins) = readdir PLUGINS; |
| 274 |
|
foreach my $plugin (@plugins) { |
| 275 |
< |
push @data, `$plugins_dir/$plugin` if -x "$plugins_dir/$plugin" && -f "$plugins_dir/$plugin"; |
| 275 |
> |
push @data, `$plugins_dir/$plugin $ostype` if -x "$plugins_dir/$plugin" && -f "$plugins_dir/$plugin"; |
| 276 |
|
} |
| 277 |
|
|
| 278 |
|
# get some extra data |
| 281 |
|
$ip = inet_ntoa(scalar(gethostbyname(hostname())) || 'localhost') or $ip = 'localhost'; |
| 282 |
|
|
| 283 |
|
# add some extra data to the array |
| 284 |
< |
push(@data, "packet.attributes.seq_no=$seq_no"); |
| 285 |
< |
push(@data, "packet.attributes.machine_name=$fqdn"); |
| 286 |
< |
push(@data, "packet.attributes.date=$date"); |
| 287 |
< |
push(@data, "packet.attributes.type=data"); |
| 288 |
< |
push(@data, "packet.attributes.ip=$ip"); |
| 284 |
> |
push(@data, "packet.attributes.seq_no $seq_no"); |
| 285 |
> |
push(@data, "packet.attributes.machine_name $fqdn"); |
| 286 |
> |
push(@data, "packet.attributes.date $date"); |
| 287 |
> |
push(@data, "packet.attributes.type data"); |
| 288 |
> |
push(@data, "packet.attributes.ip $ip"); |
| 289 |
|
|
| 290 |
+ |
# sort the data |
| 291 |
+ |
@data = sort(grep(!/^$/, grep(/^packet\./, @data))); |
| 292 |
+ |
|
| 293 |
|
# turn the array into some nice XML |
| 294 |
|
my($xml) = &make_xml("", ""); |
| 295 |
< |
|
| 295 |
> |
|
| 296 |
|
my($sock) = new IO::Socket::INET ( |
| 297 |
|
PeerPort => $udp_port, |
| 298 |
|
PeerAddr => $filter_addr, |
| 412 |
|
sub make_xml() { |
| 413 |
|
my($curlevel, $curline) = @_; |
| 414 |
|
my($xmltemp) = ""; my($curtag) = ""; my($attributes) = ""; |
| 415 |
< |
while(true) { |
| 416 |
< |
$curline = shift(@data) if $curline eq ""; chomp $curline; |
| 415 |
> |
while(1) { |
| 416 |
> |
$curline = shift(@data) if $curline eq ""; |
| 417 |
> |
return $xmltemp if not defined $curline; |
| 418 |
> |
chomp $curline; |
| 419 |
> |
# dealing with nest (or attributes) |
| 420 |
|
if($curline =~ /^$curlevel([^\.\s]+\.)/) { |
| 421 |
|
$curtag=$1; |
| 422 |
+ |
if($curline =~ /^$curlevel$curtag([^\.\s]+)\s+(.*)$/) { |
| 423 |
+ |
$xmltemp .= &make_xml("$curlevel$curtag", $curline); |
| 424 |
+ |
} |
| 425 |
+ |
elsif($curline =~ /^$curlevel$curtag(attributes)\.([^\.\s]+)\s+(.*)$/) { |
| 426 |
+ |
$attributes .= " $2=\"$3\""; |
| 427 |
+ |
} |
| 428 |
+ |
else { |
| 429 |
+ |
$xmltemp .= &make_xml("$curlevel$curtag", $curline); |
| 430 |
+ |
} |
| 431 |
+ |
my($nextline) = $data[0]; chomp $nextline if defined $nextline; |
| 432 |
+ |
$curtag =~ s/(.*)\./$1/; |
| 433 |
+ |
if((defined $nextline) && ($nextline =~ /^$curlevel$curtag\./)) { |
| 434 |
+ |
$curline = ""; |
| 435 |
+ |
} |
| 436 |
+ |
else { |
| 437 |
+ |
$xmltemp = "<$curtag$attributes>$xmltemp</$curtag>" unless $curtag eq ""; |
| 438 |
+ |
return $xmltemp; |
| 439 |
+ |
} |
| 440 |
|
} |
| 441 |
< |
if($curline =~ /^$curlevel$curtag([^\.\s]+)\s+(.*)$/) { |
| 442 |
< |
$xmltemp .= "<$1$attributes>$2</$1>"; |
| 441 |
> |
# dealing with value |
| 442 |
> |
elsif($curline =~ /^$curlevel([^\.\s]+)\s+(.*)$/) { |
| 443 |
> |
$curtag=$1; |
| 444 |
> |
$xmltemp=$2; |
| 445 |
> |
my($nextline) = $data[0]; chomp $nextline if defined $nextline; |
| 446 |
> |
if(defined $nextline && ($nextline =~ /^$curlevel$curtag\./ || $nextline =~ /^$curlevel$curtag\s+/)) { |
| 447 |
> |
$curline = ""; |
| 448 |
> |
} |
| 449 |
> |
else { |
| 450 |
> |
$xmltemp = "<$curtag$attributes>$xmltemp</$curtag>" unless $curtag eq ""; |
| 451 |
> |
return $xmltemp; |
| 452 |
> |
} |
| 453 |
|
} |
| 454 |
< |
elsif($curline =~ /^$curlevel$curtag(attributes)\.([^\.=]+)=(.*)$/) { |
| 455 |
< |
$attributes .= " $2=\"$3\""; |
| 456 |
< |
} |
| 457 |
< |
else { |
| 458 |
< |
$xmltemp .= &make_xml("$curlevel$curtag", $curline); |
| 459 |
< |
} |
| 460 |
< |
my($nextline) = $data[0]; chomp $nextline if defined $nextline; |
| 461 |
< |
$curtag =~ s/(.*)\./$1/; |
| 462 |
< |
if(defined $nextline && $nextline =~ /^$curlevel$curtag\./) { |
| 463 |
< |
$curline = ""; |
| 420 |
< |
} |
| 421 |
< |
else { |
| 422 |
< |
$xmltemp = "<$curtag$attributes>$xmltemp</$curtag>" unless $curtag eq ""; |
| 423 |
< |
return $xmltemp; |
| 424 |
< |
} |
| 454 |
> |
# dealing with a null value |
| 455 |
> |
elsif($curline =~ /^$curlevel([^\.\s]+)$/) { |
| 456 |
> |
# simply adding a space makes the above elsif deal with it :) |
| 457 |
> |
# just level with an empty tag in the XML |
| 458 |
> |
$curline .= " "; |
| 459 |
> |
} |
| 460 |
> |
# failing all that, skip the line |
| 461 |
> |
else { |
| 462 |
> |
$curline = ""; |
| 463 |
> |
} |
| 464 |
|
} |
| 465 |
|
} |