Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    Need help building Dashboard widget that displays Log file

    Scheduled Pinned Locked Moved webGUI
    4 Posts 2 Posters 1.6k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      Kruzekova
      last edited by

      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 4.2.2.2 Ping FAILED
      Tue Jan  1 04:29:56 MST 2013 8.8.8.8 Ping FAILED
      Tue Jan  1 04:30:09 MST 2013 8.8.4.4 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

      1 Reply Last reply Reply Quote 0
      • jimpJ
        jimp Rebel Alliance Developer Netgate
        last edited by

        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.

        Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

        Need help fast? Netgate Global Support!

        Do not Chat/PM for help!

        1 Reply Last reply Reply Quote 0
        • K
          Kruzekova
          last edited by

          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);
                    ?>
                   |
          
          
          1 Reply Last reply Reply Quote 0
          • jimpJ
            jimp Rebel Alliance Developer Netgate
            last edited by

            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.

            Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

            Need help fast? Netgate Global Support!

            Do not Chat/PM for help!

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.