How to add a custom menu item

Hello

I couldn’t find this anywhere, so I thought i would share how I created a persistent custom menu item in the top nav bar.

image

I saw on github that the main menu bar script already facilitates this functionality by checking if a file exists.

All you need to do is create the file

/opt/librenms/html/includes/print-menubar-custom.inc.php

and paste in

<?php
use LibreNMS\Authentication\Auth;
?>
     <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-hover="dropdown" data-toggle="dropdown"><i class="fa fa-star fa-fw fa-lg fa-nav-icons hidden-md" aria-hidden="true"></i>
        <span class="hidden-sm">Custom Menu</span></a>
          <ul class="dropdown-menu">
                <?php if (Auth::user()->hasGlobalAdmin()) { ?>
                        <li><a href="plugins/Weathermap/output/history/index.html"><i class="fa fa-film fa-fw fa-lg" aria-hidden="true"></i> Weathermap Animation</a></li>
                        <li role="presentation" class="divider"></li>
                        <li><a href="#"><i class="fa fa-database fa-fw fa-lg" aria-hidden="true"></i> Item 1</a></li>
                        <li><a href="#"><i class="fa fa-smile-o fa-fw fa-lg" aria-hidden="true"></i> Item 2</a></li>
                        <li><a href="#"><i class="fa fa-anchor fa-fw fa-lg" aria-hidden="true"></i> Item 3</a></li>
                        <li><a href="#"><i class="fa fa-plug fa-fw fa-lg" aria-hidden="true"></i> Item 4</a></li>
                        <li><a href="#"><i class="fa fa-code-fork fa-fw fa-lg" aria-hidden="true"></i> Item 5</a></li>
                        <li><a href="#"><i class="fa fa-truck fa-fw fa-lg" aria-hidden="true"></i> Item 6</a></li>

<?php } else { echo('
              <li><a href="#">You need admin rights to see this</a></li>'); } ?>
          </ul>
      </li>

Then set librenms permissions on that file

chmod librenms:librenms /opt/librenms/html/includes/print-menubar-custom.inc.php

I hope someone finds this useful :slight_smile:

8 Likes

I think you meant “chown” instead of “chmod”, but this works great. Thanks!

1 Like

ah yes thanks :smile: - for some reason i can’t edit my original post, can a mod please.

This breaks LibreNMS on the latest daily branch,

The new code, you need to replace the Auth at the top like this,

<?php
use App\Models\User;

?>
     <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-hover="dropdown" data-toggle="dropdown"><i class="fa fa-star fa-fw fa-lg fa-nav-icons hidden-md" aria-hidden="true"></i>
        <span class="hidden-sm">Custom Menu</span></a>
          <ul class="dropdown-menu">
                <?php if (Auth::user()->hasGlobalAdmin()) { ?>
                        <li><a href="plugins/Weathermap/output/history/index.html"><i class="fa fa-film fa-fw fa-lg" aria-hidden="true"></i> Weathermap Animation</a></li>
                        <li role="presentation" class="divider"></li>
                        <li><a href="#"><i class="fa fa-database fa-fw fa-lg" aria-hidden="true"></i> Item 1</a></li>
                        <li><a href="#"><i class="fa fa-smile-o fa-fw fa-lg" aria-hidden="true"></i> Item 2</a></li>
                        <li><a href="#"><i class="fa fa-anchor fa-fw fa-lg" aria-hidden="true"></i> Item 3</a></li>
                        <li><a href="#"><i class="fa fa-plug fa-fw fa-lg" aria-hidden="true"></i> Item 4</a></li>
                        <li><a href="#"><i class="fa fa-code-fork fa-fw fa-lg" aria-hidden="true"></i> Item 5</a></li>
                        <li><a href="#"><i class="fa fa-truck fa-fw fa-lg" aria-hidden="true"></i> Item 6</a></li>

<?php } else { echo('
              <li><a href="#">You need admin rights to see this</a></li>'); } ?>
          </ul>
      </li>
4 Likes

If your custom menu stopped showing on latest update, this is the fix:

Fix:

mv /opt/librenms/html/includes/print-menubar-custom.inc.php /opt/librenms/includes/html/print-menubar-custom.inc.php

Looks like path location has changed #https://github.com/librenms/librenms/commit/36431dd296af9ac8006f7c39f317ee05aa3b1029

Old location was /opt/librenms/html/includes/print-menubar-custom.inc.php

New location is /opt/librenms/includes/html/print-menubar-custom.inc.php

This functionality has been updated and the old method no longer works.

There is documentation for this now though :slight_smile:

https://docs.librenms.org/Extensions/Customizing-the-Web-UI/#custom-menu-entry

3 Likes

Epic thanks for this :slight_smile: !