Need help building Dashboard widget that displays Log file

  • I need a widget that displays the last 5 lines of a text logfile that is made from a bash script. The output of this script to the logfile is quite simple:

    Tue Jan  1 04:29:43 MST 2013 Ping FAILED
    Tue Jan  1 04:29:56 MST 2013 Ping FAILED
    Tue Jan  1 04:30:09 MST 2013 Ping FAILED
    Tue Jan  1 04:30:11 MST 2013 ALL PINGS FAILED
    Tue Jan  1 04:30:11 MST 2013 REQUESTING REBOOT…
    Tue Jan  1 04:30:11 MST 2013 DSL MODEM REBOOTING!

    I can get this in a shell with  tail -5 /var/logfile.log  but I'm not sure how to do this in a widget format.

    Thank you

  • Rebel Alliance Developer Netgate

    There are several widgets that display logs, some more complex than others. Have a look at the snort widget (in packages), havp widget (also in packages), and firewall logs widget.

    What you're after would be easier than those, they do a bit of parsing before displaying, but you could perhaps use them as a basis for what you're trying to accomplish.

    Or at least to see how widgets work in general.

  • Thank you. I looked at the code for those widgets and learned how to make my own. It is quite simple:

    $file = "/var/log/DSLModemUptimeMonitor.log";
    $contents = file($file);
    $string = array_slice($contents,-6);
    $string1 = array_reverse($string);
                            # havp version
                  echo implode("
    ", $string1);

  • Rebel Alliance Developer Netgate

    Very good, nice and simple :-)

    Eventually we'll probably have a general-purpose log widget that lets someone choose any of the files in /var/log to show in a widget. Shouldn't be too hard to do, but it's one of those things that nobody has thought to take the time for yet.

Log in to reply