--- nagios-grapher-1.6/collect2.pl 2006-06-07 18:18:55.000000000 +0200 +++ nagios-grapher-1.6_rc1-r1/collect2.pl 2006-07-03 14:48:28.000000000 +0200 @@ -207,6 +207,9 @@ # Getting XML Data $xml_hash = $ng->get_ngrapherxml(); + +# No buffered streams +$| = 1; if ($interface =~ /network/i && defined($net_port)) { # Creating a UDP socket @@ -215,20 +218,9 @@ LocalPort => $net_port, Proto => 'udp' ) || die "Creating socket faild: $@"; -} -else { - # Setting Up Named Pipe - $ng->print_log ("PRG: using FIFO") if ($opt_verbose & $LOG_PRG_STATUS); - create_pipe(); -} - -# LOOP MAIN -while (1) { - # No buffered streams - $| = 1; - # Reading from FIFO or from UDP socket. - if ($interface =~ /network/i && defined($net_port) && defined($socket)) { + # LOOP MAIN for network + while (1) { # Read from UDP socket $fifo_string = ''; @@ -241,17 +233,34 @@ $fifo_string =~ s/\\t/\t/g; $fifo_string =~ s/\\n/\n/g; - $socket->send("NagiosGrapher: thanks $s_ipaddr:$s_port.") + $socket->send("NagiosGrapher: thanks $s_ipaddr:$s_port."); + process_data($fifo_string); } - else { - # Open the PIPE and read - open( FIFO, $pipe ) - || die "Can't open pipe ($pipe)"; - $fifo_string = ; - close(FIFO); +} +else { + # Setting Up Named Pipe + $ng->print_log ("PRG: using FIFO") if ($opt_verbose & $LOG_PRG_STATUS); + create_pipe(); + # Open the pipe (and cause loosing data sucks we will never ever close it) + open( FIFO, "<$pipe" ) || die "Can't open pipe '$pipe'"; + + # LOOP MAIN for fifo + while (1) { + # Get the news out of the pipe and process them + process_data($_) while (); + # In case there is nothing left, reopen the pipe to make this process sleep while waiting for new data + open( FIFO, "<$pipe" ) || die "Failed to reopen the pipe: '$pipe'"; } +} +# There is no way out (except dying) + +# Subs: +sub process_data { + $fifo_string = shift; chomp($fifo_string); + return if ( $fifo_string eq "" ); + $ng->print_log ("PIPE: $fifo_string") if ( defined($fifo_string) && ($opt_verbose & $LOG_PIPE)); # Splitting pipe values @@ -568,12 +577,7 @@ # Clearing another values... %values = (); } -# End LOOP MAIN -# Default exit -exit(0); - -# Subs: # Helpscreen sub print_help { print "$progname: Helpscreen\n";