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: 420
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
-SN
Posts: 10
Joined: Wed Feb 25, 2026 12:39 pm

Re: Custom component registers, no menu

Post by -SN »

Kudos! Getting the component to install is most of the battle.

This snippet would place the component link in the Home Menu under Maps

Code: Select all

/*
 *  Adds the index page to the menu
 */
function saturationreport_component_addmenu()
{
    global $saturationreport_component_name;

    $component_url = get_component_url_base($saturationreport_component_name);

    // find the location of menu of network status map
    $menu_section = find_menu_item(MENU_HOME, "menu-home-section-maps", "id");
    if ($menu_section == null) {
        return false;
    }
    $order = grab_array_var($menu_section, "order", "");
    
    // Make this the top item in the maps section
    $new_order = $order + 0.1;
    if ($new_order < 0) {
        return false;
    }

    add_menu_item(MENU_HOME, array(
        "type"  => "link",
        "title" => _("Storage Saturation Report"),
        "id"    => "menu-home-section-saturationreport",
        "order" => $new_order,
        "opts"  => array(
            "href" => $component_url . "/index.php",
            "icon" => "fa-file-text-o",
        )
    ));

    add_menu_item(MENU_HOME, array(
        "type"  => "linkspacer",
        "id"    => "menu-home-section-saturationreport-spacer",
        "order" => $new_order+0.1
    ));
}
In XI you would see this in the Home menu under Maps
menu_maps.PNG
Authentication functions and order of operation are important.

Code: Select all

<?php
// Required includes for web-accessible component scripts
require_once(dirname(__FILE__).'/../../common.inc.php');

// Initialization sequence (in order)
pre_init();              // Initialization stuff
init_session();          // Start session
grab_request_vars();     // Grab GET or POST variables
check_prereqs();         // Check prerequisites
check_authentication(false); // Check authentication (false = don't redirect for API)
```

Why This Order Matters:
- `pre_init()`: Sets up basic environment
- `init_session()`: Starts PHP session (must be before any output)
- `grab_request_vars()`: Safely retrieves form variables
- `check_prereqs()`: Verifies system prerequisites
- `check_authentication()`: Validates user is logged in

### Authentication Functions

check_authentication($redirect = true):
- Checks if user is authenticated
- If not authenticated and `$redirect` is `true`, redirects to login page
- If `$redirect` is `false`, returns without redirecting (useful for API endpoints)
- Must be called after `init_session()`

is_authenticated():
- Returns `true` if user is logged in, `false` otherwise
- Does not redirect
- Useful for conditional logic

is_admin():
- Returns `true` if current user has admin privileges
- Useful for restricting access to admin-only features

 get_user_id():
- Returns the current user's ID
- Useful for user-specific data

### Example: Protected Page
<?php
require_once(dirname(__FILE__).'/../../common.inc.php');

pre_init();
init_session();
grab_request_vars();
check_prereqs();
check_authentication(); // Redirects to login if not authenticated

// Check for admin privileges
if (!is_admin()) {
    echo "Access denied. Admin privileges required.";
    exit;
}

// Page content here

Happy Monitoring!
--SN
You do not have the required permissions to view the files attached to this post.
Post Reply