Custom component registers, no menu

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Post Reply
dchatham
Posts: 1
Joined: Wed Aug 30, 2023 9:21 am

Custom component registers, no menu

Post by dchatham »

Following this guide: https://support.nagios.com/kb/article/n ... s-291.html

The component registers, is listed in "Manage Components". I cannot get it to show up in any menu I have tried to attach it to.

Pertinent code:
function customnotifications_component_addmenu($arg = null)
{
if (is_readonly_user(0)) {
return;
}

global $customnotifications_component_name;
$urlbase = get_component_url_base($customnotifications_component_name);

$mi = find_menu_item ( MENU_ACCOUNT, "menu-account-customtemplates", "id" );

if ($mi == null) {
return;
}

$order = grab_array_var($mi, "order", "");
if ($order == "") {
return;
}

$neworder = $order + 1.1;

add_menu_item(MENU_ACCOUNT, array(
"type" => "link",
"title" => _("Custom Notification Templates"),
"id" => "menu-account-customtemplates",
"order" => $neworder,
"opts" => array(
"href" => $urlbase . "/index.php"
),
"function" => "customnotifications_can_show_menu"
));
}
Help me, Obi won kenobi, you're my only hope.
User avatar
lgute
Posts: 410
Joined: Mon Apr 06, 2020 2:49 pm

Re: Custom component registers, no menu

Post by lgute »

Hi @dchatham,

Thanks for reaching out. I'm not sure what distro/version you are running XI on, so I'm going to assume RHEL based. The first thing I would do is check the /var/log/php-fpm/www-error.log. On other distros this output will be in the Apache error log.

If that doesn't help, add error_log() comments so you can see what the variables are set to and if the function is exiting sooner than you think.

I asked the "robot" and got these other suggestions.
If your Nagios XI custom component is not appearing in the menu, the most common causes are incorrect configuration, missing or conflicting id values, or improper placement in the menu hierarchy.

Check the id in your component's registration script: Ensure the id is unique and correctly defined in the component.inc.php file. Duplicate or invalid id values can cause components to be ignored or override others.
Verify the add_menu_item function in inc.php: Use the correct menu constant (e.g., MENU_HOME) and ensure the id matches an existing menu item for proper placement. For example:
$mi = find_menu_item(MENU_HOME, "menu-home-tacticaloverview", "id");
if ($mi == null) return;

If the referenced menu item doesn’t exist, the component may fail silently.
  • Confirm the component is uploaded and enabled: Go to Admin > System Extensions > Manage Components, upload your .zip file, and ensure the component is enabled and not disabled.
  • Check for conflicting CSS or JS: If using Custom Includes, ensure no CSS rules are hiding the menu item. Also, verify that no existing component (e.g., Header-Solid.css) is conflicting with your custom styles.
    Review the Apache error log: Use tail -f /usr/local/nagiosxi/logs/httpd/error_log to check for PHP errors or file not found issues (e.g., missing image or script).
  • Use the correct menu order: Components are added based on the order value. If the order is incorrect or conflicts with existing items, it may appear out of place or not load.
  • Test with a minimal component: Create a simple component with only the add_menu_item function to isolate the issue.
For detailed guidance, refer to the official documentation:
Please let us know if you have any other questions or concerns.

-Laura
Post Reply