#!/usr/bin/perl # dialdmon by David Efflandt - tech@de-srv.com # Monitors diald with 20 most recent queue entries. # For more info see 'man diald-monitor' and 'man diald-control'. # ^C (Ctrl-C) to exit. use English; my $control = '/etc/diald/diald.ctl'; my $monitor = '/etc/diald/diald.mon'; my $dialdpid = '/var/run/diald.pid'; my $sleep_count = 0; # Check if diald is running and has control FIFO -e $dialdpid || die "diald is not running (no $dialdpid)\n"; -p $control || die "no diald-control pipe ($control)\n"; # Check or create FIFO (named pipe) unless (-p $monitor) { unlink $monitor; system('mknod', $monitor, 'p') && die "Can't mknod $monitor: $!"; } # Open FIFO required for monitor, open blocks, so we fork. do { $pid = open(KIN, "-|"); unless (defined $pid) { warn "cannot fork: $!"; die "bailing out" if $sleep_count++ > 6; sleep 10; } } until defined $pid; unless ($pid) { # we are the child $| = 1; print "Opening FIFO for monitor\n"; # tell parent we are ready open (M, "< $monitor") || die "Can't open $monitor: $!"; print "FIFO opened for monitor\n\n"; while () { print; } close M; exit; } # Else we are the parent $_ = ; # Verify that child is ready print; # FIFO is up so we can start diald monitor open (C, ">> $control") || die "Can't open $control: $!"; print C "monitor $monitor\n"; close C; # Read from child and print while () { if (/STATUS/) { print "\n$_"; $up = ; if ($up > 0) { $up = 'Up ' } else { $up = 'Down' } $force = ; chomp $force; $im = ; chomp $im; $im_itm = ; chomp $im_itm; $im_tm = ; chomp $im_tm; $im_fuzz = ; chomp $im_fuzz; $im_to = ; chomp $im_to; $force_to = ; chomp $force_to; $to = ; chomp $to; print "$up Force: $force Impulse_Mode: $im Imp1: $im_itm ", "Imp2: $im_tm Fuzz: $im_fuzz\nIm_To: $im_to ", "Force To: $force_to Next: $to\n"; } elsif (/QUEUE/) { print; my $i = 0; while () { last if /END QUEUE/; print if $i++ < 20; } } elsif (/LOAD/) { chomp; $itxtotal = ; chomp $itxtotal; $irxtotal = ; chomp $irxtotal; print "$_ Tx bytes: $itxtotal Rx bytes: $irxtotal\n"; } elsif (/STATE/) { chomp; $_ .= ': '.; print; } else { print $_; } } close(KIN) || warn "kid exited $?";