" . _('Error: This component requires Nagios XI 1.1.4 or later.') . ""; } $args = array( COMPONENT_NAME => $saturationreport_component_name, COMPONENT_AUTHOR => "snapier", COMPONENT_DESCRIPTION => $desc, COMPONENT_TITLE => _('Storage Saturation Report'), COMPONENT_VERSION => '1.0.0', COMPONENT_DATE => '01/18/2026', ); register_component($saturationreport_component_name, $args); if ( saturationreport_check_version() ) { register_callback(CALLBACK_MENUS_INITIALIZED, 'saturationreport_component_addmenu'); } } /* * Checks to see if the component is compatible with the version of XI */ function saturationreport_check_version() { if ( function_exists('get_product_release') ) { if (get_product_release() >= 5600) { return true; } } return false; } /* * Check Python dependencies for export functionality */ function saturationreport_check_python_dependencies() { // Try to detect Python 3 $python_commands = array('python3', '/usr/bin/python3', 'python', '/usr/bin/python'); $python_cmd = null; foreach ($python_commands as $cmd) { $versionString = @shell_exec($cmd . ' -c "import sys; print(sys.version_info[0])" 2>/dev/null'); if ($versionString !== null && trim($versionString) !== '') { $pythonVersion = (int) trim($versionString); if ($pythonVersion >= 3) { $python_cmd = $cmd; break; } } } if (!$python_cmd) { return array( 'python_available' => false, 'error' => 'Python 3 not found. Export functionality will not work.' ); } // Check for required modules $weasyprint_ok = false; $pillow_ok = false; $pdf2image_ok = false; $check_cmd = escapeshellarg($python_cmd) . ' -c ' . escapeshellarg("import weasyprint; print('OK')") . ' 2>/dev/null'; $check_output = @shell_exec($check_cmd); if ($check_output !== null && trim($check_output) === 'OK') { $weasyprint_ok = true; } $check_cmd = escapeshellarg($python_cmd) . ' -c ' . escapeshellarg("import PIL; print('OK')") . ' 2>/dev/null'; $check_output = @shell_exec($check_cmd); if ($check_output !== null && trim($check_output) === 'OK') { $pillow_ok = true; } $check_cmd = escapeshellarg($python_cmd) . ' -c ' . escapeshellarg("import pdf2image; print('OK')") . ' 2>/dev/null'; $check_output = @shell_exec($check_cmd); if ($check_output !== null && trim($check_output) === 'OK') { $pdf2image_ok = true; } $all_ok = $weasyprint_ok && $pillow_ok && $pdf2image_ok; return array( 'python_available' => true, 'python_cmd' => $python_cmd, 'weasyprint_installed' => $weasyprint_ok, 'pillow_installed' => $pillow_ok, 'pdf2image_installed' => $pdf2image_ok, 'all_dependencies_ok' => $all_ok, 'error' => $all_ok ? null : 'Some Python packages are missing. Install with: pip3 install weasyprint Pillow pdf2image' ); } /* * 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 )); }