$name, CONFIGWIZARD_VERSION => "3.0.8", CONFIGWIZARD_TYPE => CONFIGWIZARD_TYPE_MONITORING, CONFIGWIZARD_DESCRIPTION => _("Monitor a host (Windows, Linux, OS X, Solaris, or AIX) using the Nagios Cross-Plaftorm Agent.") . '
centos rhel sles suse opensuse oracle cloudlinux ubuntu debian redhat mac
', CONFIGWIZARD_DISPLAYTITLE => _("NCPA / VMware"), CONFIGWIZARD_FUNCTION => "ncpa_vmware_configwizard_func", CONFIGWIZARD_PREVIEWIMAGE => "ncpa.png", CONFIGWIZARD_FILTER_GROUPS => array('nagios','windows','linux','otheros'), CONFIGWIZARD_REQUIRES_VERSION => 5700 ); register_configwizard($name, $args); } /** * @param string $mode * @param null $inargs * @param $outargs * @param $result * * @return string */ function ncpa_vmware_configwizard_func($mode = "", $inargs = null, &$outargs, &$result, $extra = array()) { $wizard_name = "ncpa_vmware"; // Initialize return code and output $result = 0; $output = ""; // Initialize output args - pass back the same data we got $outargs[CONFIGWIZARD_PASSBACK_DATA] = $inargs; switch ($mode) { case CONFIGWIZARD_MODE_GETSTAGE1HTML: $os = "windows"; $ip_address = grab_array_var($inargs, "ip_address", ""); $port = grab_array_var($inargs, "port", "5693"); $token = grab_array_var($inargs, "token", ""); $no_ssl_verify = grab_array_var($inargs, "no_ssl_verify", 1); $vcenter_host = grab_array_var($inargs, "vcenter_host", ""); $vcenter_port = grab_array_var($inargs, "vcenter_port", 443); $vcenter_no_ssl_verify = grab_array_var($inargs, "vcenter_no_ssl_verify", 1); $vcenter_vmname = grab_array_var($inargs, "vcenter_vmname", ""); $vcenter_username = grab_array_var($inargs, "vcenter_username", ""); $vcenter_password = grab_array_var($inargs, "vcenter_password", ""); $ip_address = grab_array_var($inargs, "ip_address", "192.168.0.38"); $port = grab_array_var($inargs, "port", "5693"); $token = grab_array_var($inargs, "token", "mytoken"); $no_ssl_verify = grab_array_var($inargs, "no_ssl_verify", 1); $vcenter_host = grab_array_var($inargs, "vcenter_host", "192.168.0.25"); $vcenter_port = grab_array_var($inargs, "vcenter_port", 443); $vcenter_no_ssl_verify = grab_array_var($inargs, "vcenter_no_ssl_verify", 1); $vcenter_vmname = grab_array_var($inargs, "vcenter_vmname", "inner_centos"); $vcenter_username = grab_array_var($inargs, "vcenter_username", "root"); $vcenter_password = grab_array_var($inargs, "vcenter_password", "Welcome1."); $output = '
' . _('Setup NCPA') . '

' . _('The agent should be installed before you continue running this wizard.') . '

' . _('Connect to NCPA') . '
' . _('The IP address or FQDNS name used to connect to NCPA') . '.
' . _('Port used to connect to NCPA. Defaults to port 5693') . '.
' . _('Authentication token used to connect to NCPA') . '.
Connect to vCenter
The IP address or FQDNS name used to connect to vCenter.
Port used to connect to vCenter. Defaults to port 443.
The name of the virtual machine.
Username to connect to vCenter as.
Password for vCenter username.
'; break; case CONFIGWIZARD_MODE_VALIDATESTAGE1DATA: // Get variables that were passed to us $ip_address = grab_array_var($inargs, "ip_address", ""); $port = grab_array_var($inargs, "port", "5693"); $token = grab_array_var($inargs, "token", ""); $no_ssl_verify = grab_array_var($inargs, "no_ssl_verify", 1); $vcenter_host = grab_array_var($inargs, "vcenter_host", ""); $vcenter_port = intval(grab_array_var($inargs, "vcenter_port", 443)); $vcenter_no_ssl_verify = grab_array_var($inargs, "vcenter_no_ssl_verify", 1); $vcenter_vmname = grab_array_var($inargs, "vcenter_vmname", ""); $vcenter_username = grab_array_var($inargs, "vcenter_username", ""); $vcenter_password = grab_array_var($inargs, "vcenter_password", ""); // For multi-host ncpa run (from deployment) $hosts = grab_request_var("hosts", array()); $job_id = grab_request_var("job_id", 0); // Grab deploy id if it exists $deploy_id = grab_request_var('deploy_id', 0); if (!empty($deploy_id)) { $agent = deploy_get_agent($deploy_id); $metadata = json_decode(base64_decode($agent['metadata']), true); $token = decrypt_data($metadata['token']); $ip_address = $agent['address']; } // Check for errors $errors = 0; $errmsg = array(); if (have_value($ip_address) == false && empty($hosts)) { $errmsg[$errors++] = _("No address specified."); } if (have_value($port) == false) { $errmsg[$errors++] = _("No port number specified."); } if (have_value($vcenter_host) == true && empty($vcenter_vmname)) { $errmsg[$errors++] = "vCenter host given, but no vmname."; } if (have_value($vcenter_host) == true && empty($vcenter_username)) { $errmsg[$errors++] = "vCenter host given, but no username."; } if (have_value($vcenter_host) == true && empty($vcenter_password)) { $errmsg[$errors++] = "vCenter host given, but no password."; } if (have_value($vcenter_host) == true && $vcenter_port <= 0) { $errmsg[$errors++] = "vCenter host given with impossible port number."; } // Test the connection if no errors if (empty($errors) && empty($hosts)) { $ip_address_replaced = nagiosccm_replace_user_macros($ip_address); $port_replaced = nagiosccm_replace_user_macros($port); $token_replaced = nagiosccm_replace_user_macros($token); // The URL we will use to query the NCPA agent, and do a walk // of all monitorable items. $query_url = "https://{$ip_address}:{$port}/testconnect/?token=".urlencode($token); $query_url_replaced = "https://{$ip_address_replaced}:{$port_replaced}/testconnect/?token=".urlencode($token_replaced); // Remove SSL verification or not $context = array("ssl" => array("verify_peer" => true, "verify_peer_name" => true)); if ($no_ssl_verify) { $context['ssl']['verify_peer'] = false; $context['ssl']['verify_peer_name'] = false; } // All we want to do is test if we can hit this URL. $raw_json = file_get_contents($query_url_replaced, false, stream_context_create($context)); if (empty($raw_json)) { $errmsg[$errors++] = _("Unable to contact server at") . " {$query_url}."; } else { $json = json_decode($raw_json, true); if (!array_key_exists('value', $json)) { $errmsg[$errors++] = _("Bad token for connection."); } } } if ($errors > 0) { $outargs[CONFIGWIZARD_ERROR_MESSAGES] = $errmsg; $result = 1; } break; case CONFIGWIZARD_MODE_GETSTAGE2HTML: // Get variables that were passed to us $ip_address = grab_array_var($inargs, "ip_address", ""); $port = grab_array_var($inargs, "port", "5693"); $token = grab_array_var($inargs, "token", ""); $no_ssl_verify = grab_array_var($inargs, "no_ssl_verify", 1); $hostname = grab_array_var($inargs, 'hostname', @gethostbyaddr($ip_address)); $default_mem_units = grab_array_var($inargs, 'default_mem_units', 'Gi'); $vcenter_host = grab_array_var($inargs, "vcenter_host", ""); $vcenter_port = intval(grab_array_var($inargs, "vcenter_port", 443)); $vcenter_no_ssl_verify = grab_array_var($inargs, "vcenter_no_ssl_verify", 1); $vcenter_vmname = grab_array_var($inargs, "vcenter_vmname", ""); $vcenter_username = grab_array_var($inargs, "vcenter_username", ""); $vcenter_password = grab_array_var($inargs, "vcenter_password", ""); // Run our get-vm-disks.py script if ($vcenter_host != "") { $get_vm_disks_cmd = "python3 " . get_base_dir() . "/includes/configwizards/ncpa_vmware/get-vm-disks.py "; $get_vm_disks_cmd .= "--host $vcenter_host --port $vcenter_port "; $get_vm_disks_cmd .= "--user $vcenter_username --password \"$vcenter_password\" "; $get_vm_disks_cmd .= "--vm-name $vcenter_vmname"; if ($vcenter_no_ssl_verify == 1) { $get_vm_disks_cmd .= " --skip-ssl"; } if (exec($get_vm_disks_cmd, $get_vm_disks_cmd_output, $get_vm_disks_rc) !== false) { if ($get_vm_disks_rc == 0) { $disks_json = implode("", $get_vm_disks_cmd_output); $disks = json_decode($disks_json, true); } } } // Set os to extra os $os = grab_array_var($inargs, "os", "windows"); // For multi-host ncpa run (from deployment) $hosts = grab_request_var("hosts", array()); $job_id = grab_request_var("job_id", 0); if (!empty($job_id)) { if (count($hosts) == 1) { $job = deploy_get_job($job_id); $token = decrypt_data($job['ncpa_token']); $ip_address = $hosts[0]; $hostname = gethostbyaddr($ip_address); $hosts = array(); $os = $job['os']; } else { // Don't set the normal things because it's multi-host... } } // Grab deploy id if it exists $deploy_id = grab_request_var('deploy_id', 0); if (!empty($deploy_id)) { $agent = deploy_get_agent($deploy_id); $metadata = json_decode(base64_decode($agent['metadata']), true); $token = decrypt_data($metadata['token']); $ip_address = $agent['address']; $hostname = $agent['hostname']; $os = $agent['os']; } $rp_address = nagiosccm_replace_user_macros($ip_address); $rp_port = nagiosccm_replace_user_macros($port); $rp_token = nagiosccm_replace_user_macros($token); $services = grab_array_var($inargs, "services", array()); $services_serial = grab_array_var($inargs, "services_serial", ""); if ($services_serial) { $services = unserialize(base64_decode($services_serial)); } $categories = array(); $root = array(); // If we are running the wizard on a single host, get the proper data // otherwise we need to use generic data if (empty($hosts)) { $api_url = "https://{$rp_address}:{$rp_port}/api"; $interface_data = ncpa_vmware_configwizard_get_api_data('interface', $api_url, $rp_token, $no_ssl_verify); $disk_data = ncpa_vmware_configwizard_get_api_data('disk', $api_url, $rp_token, $no_ssl_verify); $service_data = ncpa_vmware_configwizard_get_api_data('services', $api_url, $rp_token, $no_ssl_verify); $process_data = ncpa_vmware_configwizard_get_api_data('processes', $api_url, $rp_token, $no_ssl_verify); $plugin_data = ncpa_vmware_configwizard_get_api_data('plugins', $api_url, $rp_token, $no_ssl_verify); $cpu_data = ncpa_vmware_configwizard_get_api_data('cpu/percent', $api_url, $rp_token, $no_ssl_verify, array('aggregate' => 'avg')); $user_data = ncpa_vmware_configwizard_get_api_data('user/count', $api_url, $rp_token, $no_ssl_verify); $mem_data = ncpa_vmware_configwizard_get_api_data('memory/virtual/percent', $api_url, $rp_token, $no_ssl_verify); $swap_data = ncpa_vmware_configwizard_get_api_data('memory/swap/percent', $api_url, $rp_token, $no_ssl_verify); } else { $disk_data = array('' => ''); $interface_data = array('' => ''); $service_data = array(); $process_data = array(); $plugin_data = array(); } $root['disk'] = $disk_data; $root['interface'] = $interface_data; $root['services'] = $service_data; // Set up processes $tmp = array(); foreach ($process_data as $p) { if (array_key_exists($p['name'], $tmp)) { $tmp[$p['name']]++; } else { $tmp[$p['name']] = 1; } } $root['processes'] = $tmp; // Sort plugin data if (!empty($plugin_data)) { sort($plugin_data); } $root['plugins'] = $plugin_data; $icon = _("Generic"); if (!empty($os)) { $icon = ''; } $output = ' '; if (!empty($hosts)) { $output .= '
' . _("Host Information") . '

' . _('Adding the following service checks to the below hosts.') . '

'; foreach ($hosts as $host) { $output .= ''; $output .= ''; $output .= ''; } $output .= '
' . _('Hostname') . '
' . encode_form_val($host) . '
'; } else { $output .= '
' . _("Host Information") . '
' . _("The hostname you'd like to have associated with this host") . '.
'.$icon.'
'; } $defaults = grab_array_var($extra, "defaults", ""); // Set defaults for services $default_services['cpu_usage']['monitor'] = 'on'; $default_services['cpu_usage']['warning'] = 20; $default_services['cpu_usage']['critical'] = 40; $default_services['cpu_usage']['average'] = 1; $default_services['users']['monitor'] = 'on'; $default_services['users']['warning'] = 2; $default_services['users']['critical'] = 4; $default_services['memory_usage']['monitor'] = 'on'; $default_services['memory_usage']['warning'] = 50; $default_services['memory_usage']['critical'] = 80; $default_services['swap_usage']['monitor'] = 'on'; $default_services['swap_usage']['warning'] = 5; $default_services['swap_usage']['critical'] = 10; if (isset($root['disk']['logical'])) { $id = 0; foreach ($root['disk']['logical'] as $title => $value) { if (empty($value['device_name'])) { continue; } $default_services['disk'][$id]['monitor'] = 'on'; $default_services['disk'][$id]['warning'] = 70; $default_services['disk'][$id]['critical'] = 90; $default_services['disk'][$id]['name'] = $value['device_name']; if (is_array($value['device_name'])) { $default_services['disk'][$id]['name'] = $value['device_name'][0]; } $default_services['disk'][$id]['title'] = $title; $id++; } } else if (!empty($hosts)) { $default_services['disk'][0]['monitor'] = 'on'; $default_services['disk'][0]['warning'] = 70; $default_services['disk'][0]['critical'] = 90; $default_services['disk'][0]['name'] = "/"; } ksort($root['interface']); $id = 0; foreach ($root['interface'] as $title => $value) { if (stripos($title, "Local Area Connection") !== false || stripos($title, "eth") !== false || stripos($title, "ens") !== false || stripos($title, "Wireless") !== false) { $default_services['interface'][$id]['monitor'] = 'on'; } else { $default_services['interface'][$id]['monitor'] = 'off'; } $default_services['interface'][$id]['warning'] = 10; $default_services['interface'][$id]['critical'] = 100; $default_services['interface'][$id]['name'] = $title; $id++; } // Create defaults for processes if ($defaults == "desktop") { // Add explorer $default_services['process'][] = array( 'monitor' => 'off', 'name' => 'explorer.exe', 'desc' => 'Explorer', 'warning' => '', 'critical' => '1:' ); } $default_services['process'][] = array( 'monitor' => 'off', 'name' => '', 'desc' => '', 'warning' => '', 'critical' => '' ); // Create defaults for services if ($defaults == "desktop" || $defaults == "server") { // MSSQL server defaults if (array_key_exists('MSSQLSERVER', $root['services'])) { $default_services['services'][] = array( 'monitor' => 'off', 'name' => 'MSSQLSERVER', 'desc' => 'MSSQL Service Status', 'state' => 'running' ); } else if (array_key_exists('MSSQL$SQLEXPRESS', $root['services'])) { $default_services['services'][] = array( 'monitor' => 'off', 'name' => 'MSSQL$SQLEXPRESS', 'desc' => 'MSSQL Express Service Status', 'state' => 'running' ); } // Windows Defender running if (array_key_exists('WinDefend', $root['services'])) { $default_services['services'][] = array( 'monitor' => 'off', 'name' => 'WinDefend', 'desc' => 'Windows Defender Service', 'state' => 'running' ); } // MSSQL telemetry defaults if (array_key_exists('MSSQLTELEMETRY', $root['services'])) { $default_services['services'][] = array( 'monitor' => 'off', 'name' => 'MSSQLTELEMETRY', 'desc' => 'MSSQL Telemetry Service Status', 'state' => 'running' ); } else if (array_key_exists('SQLTELEMETRY$SQLEXPRESS', $root['services'])) { $default_services['services'][] = array( 'monitor' => 'off', 'name' => 'SQLTELEMETRY$SQLEXPRESS', 'desc' => 'MSSQL Express Telemetry Service Status', 'state' => 'running' ); } // IIS server defaults if ($defaults == "server") { if (array_key_exists('WAS', $root['services'])) { $default_services['services'][] = array( 'monitor' => 'off', 'name' => 'WAS', 'desc' => 'Windows Process Activation Service Status', 'state' => 'running' ); } if (array_key_exists('W3SVC', $root['services'])) { $default_services['services'][] = array( 'monitor' => 'off', 'name' => 'W3SVC', 'desc' => 'IIS Web Publishing Service Status', 'state' => 'running' ); } } } $default_services['services'][] = array( 'monitor' => 'off', 'name' => '', 'desc' => '', 'state' => 'running' ); // Create defaults for counters if ($defaults == "desktop" || $defaults == "server") { $default_services['counters'][] = array( 'monitor' => 'off', 'name' => '\Paging File(*)\% Usage', 'desc' => _('Paging File Usage'), 'sleep' => '', 'warning' => 70, 'critical' => 90 ); $default_services['counters'][] = array( 'monitor' => 'off', 'name' => '\Event Log\Events/sec', 'desc' => _('Event Log Events/sec'), 'sleep' => 5, 'warning' => 10, 'critical' => 20 ); $default_services['counters'][] = array( 'monitor' => 'off', 'name' => '\Terminal Services\Active Sessions', 'desc' => _('Active Terminal Sessions'), 'sleep' => '', 'warning' => 2, 'critical' => 3 ); $default_services['counters'][] = array( 'monitor' => 'off', 'name' => '\System\Threads', 'desc' => _('Number of System Threads'), 'sleep' => '', 'warning' => '', 'critical' => '' ); if ($defaults == "desktop") { $default_services['counters'][] = array( 'monitor' => 'off', 'name' => '\Print Queue(*)\Job Errors', 'desc' => _('Print Queue Job Errors'), 'sleep' => '', 'warning' => 1, 'critical' => 2 ); $default_services['counters'][] = array( 'monitor' => 'off', 'name' => '\Telephony\Active Lines', 'desc' => _('Active Telephony Lines'), 'sleep' => '', 'warning' => '', 'critical' => '' ); } else { $default_services['counters'][] = array( 'monitor' => 'off', 'name' => '\Server\Errors Logon', 'desc' => _('Logon Errors'), 'sleep' => '', 'warning' => 2, 'critical' => 20 ); $default_services['counters'][] = array( 'monitor' => 'off', 'name' => '\Server Work Queues(0)\Queue Length', 'desc' => _('Server Work Queues'), 'sleep' => '', 'warning' => 4, 'critical' => 7 ); } } $default_services['counters'][] = array( 'monitor' => 'off', 'name' => '', 'desc' => '', 'sleep' => '', 'warning' => '', 'critical' => '' ); // Create only one plugin if no plugins saved $default_services['plugins'][0]['monitor'] = 'off'; $default_services['plugins'][0]['name'] = ''; $default_services['plugins'][0]['desc'] = ''; $default_services['plugins'][0]['args'] = ''; if (empty($services)) { $services = $default_services; } $output .= '
' . _("System Metrics") . '

' . _("Specify the metrics you'd like to monitor on the NCPA Agent") . '.

'; if (!empty($cpu_data)) { $output .= ' '; } $output .= ' '; if (!empty($user_data)) { $output .= ' '; } $output .= '
' . _('Check the CPU usage of the system') . '.
%   %
%
' . _('Check the number of users currently logged into the system') . '.
#   #
' . _('Memory Metrics') . '

' . _('Default units to use for memory metric ouput') . ':

'; if (!empty($mem_data)) { $output .= ' '; } $output .= ' '; if (!empty($swap_data)) { $output .= ' '; } $curr_usage = ''; if (empty($hosts)) { $curr_usage = ''; } $vmware_disk = ''; if (!empty($vcenter_host)) { $vmware_disk = ''; } $output .= '
%   %
%
%   %
%
' . _("Disk Metrics") . '

' . _("Specify the disks the the warning and critical percentages for disk capacity") . '.

'; if (!empty($hosts)) { $output .= '

'._('Disk checks specified will be applied to all hosts. If the disk name does not exist it will show CRITICAL.').'

'; } $output .= ' '.$curr_usage.' '.$vmware_disk.' '; $disabled = ' readonly'; if (!empty($hosts)) { $disabled = ''; } $id = 0; foreach ($services['disk'] as $id => $metrics) { $title = !empty($metrics['title']) ? $metrics['title'] : $metrics['name']; $titleout = str_replace('|', '\\', $title); $disk_usage = ""; if (array_key_exists('total', $root['disk']['logical'][$title])) { $disk_total = $root['disk']['logical'][$title]['total'][0].' '.$root['disk']['logical'][$title]['total'][1].' '._('Total'); $disk_usage = ''; } $vmware_disk = ''; if (!empty($vcenter_host)) { $vmware_disk = ''; $vmware_disk .= ' '; } $output .= ' '.$disk_usage.' '.$vmware_disk.' '; $id++; } $output .= '
%  
%   %
'; if (!empty($hosts)) { $output .= '

'._("Add Disk Check").'

'; } $output .= '
' . _('Network Interface Metrics') . '

' . _("Specify bandwidth limits for your network interfaces. Note that these measurements are per second, not a counter.") . '

'; if (empty($hosts)) { $output .= ' '; } else { $output .= '

'._('Interface checks specified will be applied to all hosts. If the interface name does not exist it will show CRITICAL.').'

'; } $output .= ' '; $disabled = ' readonly'; if (!empty($hosts)) { $disabled = ''; } $id = 0; $hidden = false; foreach ($services['interface'] as $id => $metrics) { $hide = ''; $title = $metrics['name']; if (!is_checked(grab_array_var($services['interface'][$id], 'monitor'), 'on') && empty($hosts)) { $hide = 'class="hidden-interface hide"'; } $output .= ' '; $id++; } $output .= '
MB/s   MB/s
'; if (empty($hosts)) { $output .= '

'._("Show all interfaces").'

'; } else { $output .= '

'._("Add Interface Check").'

'; } $output .= '
' . _("Services") . '

' . _("Specify which services should be running or stopped. Depending on the selected state you will recieve an OK when the process is in the selected state and a CRITICAL if the process is not in the state selected.") . '

'; foreach ($services['services'] as $i => $metrics) { $services_selector = ''; if (empty($hosts)) { $services_selector = '
'; } $output .= ' '; } // Create a list of services for the JS $service_list = ''; ksort($root['services']); foreach ($root['services'] as $service => $status) { $service_list .= ''; } // Create a list of processes for the JS $processes_list = ''; ksort($root['processes']); foreach ($root['processes'] as $process => $amount) { $processes_list .= ''; } // Create a list of plugins for the JS $plugin_list = ''; if (!empty($root['plugins'])) { $plugin_list .= ''; } else { $plugin_list .= '
'._('No plugins found on the agent system') . '
'; } $output .= '
'.$services_selector.'
'._('Add Another Service Check').'
' . _('Processes') . '

' . _("Specify which processes should be running and how many of them there should be.") . '

'; foreach ($services['process'] as $i => $metrics) { $select_process = ''; if (empty($hosts)) { $select_process = '
'; } $output .= ' '; } $process_selector = ''; $service_selector = ''; $plugin_selector = ''; if (empty($hosts)) { $process_selector = '
'; $service_selector = '
'; $plugin_selector = '
'; } $output .= '
'.$select_process.'
  
'._('Add Another Process Check').'
'; if ($os == "windows") { $output .= '
' . _('Windows Counters') . '

' . _("Specify any windows counters you would like NCPA to check the value of. Per second counters require a sleep time.") . '

'; foreach ($services['counters'] as $i => $metrics) { $output .= ' '; } $output .= '
  
'._('Add Another Windows Counter Check').'
'; } $output .= '
' . _('Plugins') . '

' . _("If you have provided plugins on the client that you would like NCPA to run, specify them and the arguments to be passed here.") . '

'; foreach ($services['plugins'] as $i => $metrics) { $plugin_selector = ''; if (empty($hosts)) { $plugin_selector = '
'; } $output .= ' '; } $output .= '
'.$plugin_selector.'
'._('Add Another Plugin Check').'
'; break; case CONFIGWIZARD_MODE_VALIDATESTAGE2DATA: // Get variables that were passed to us $ip_address = grab_array_var($inargs, 'ip_address'); $hostname = grab_array_var($inargs, 'hostname'); $port = grab_array_var($inargs, 'port'); $token = grab_array_var($inargs, 'token'); $default_mem_units = grab_array_var($inargs, 'default_mem_units'); $vcenter_host = grab_array_var($inargs, "vcenter_host", ""); $vcenter_port = intval(grab_array_var($inargs, "vcenter_port", 443)); $vcenter_no_ssl_verify = grab_array_var($inargs, "vcenter_no_ssl_verify", 1); $vcenter_vmname = grab_array_var($inargs, "vcenter_vmname", ""); $vcenter_username = grab_array_var($inargs, "vcenter_username", ""); $vcenter_password = grab_array_var($inargs, "vcenter_password", ""); $vmdisk_info = grab_array_var($inargs, "vmdisk_info", ""); $hosts = grab_array_var($inargs, "hosts", array()); $job_id = grab_array_var($inargs, "job_id", 0); // Check for errors $errors = 0; $errmsg = array(); if (empty($hosts) && is_valid_host_name($hostname) == false) { $errmsg[$errors++] = "Invalid host name."; } if ($errors > 0) { $outargs[CONFIGWIZARD_ERROR_MESSAGES] = $errmsg; $result = 1; } break; case CONFIGWIZARD_MODE_GETSTAGE3HTML: // Get variables that were passed to us $ip_address = grab_array_var($inargs, 'ip_address'); $hostname = grab_array_var($inargs, 'hostname'); $port = grab_array_var($inargs, 'port'); $token = grab_array_var($inargs, 'token'); $services = grab_array_var($inargs, 'services', array()); if (empty($services)) { $services_serial = grab_array_var($inargs, "services_serial", ""); $services = unserialize(base64_decode($services_serial)); } $default_mem_units = grab_array_var($inargs, 'default_mem_units'); $os = grab_array_var($inargs, 'os', ''); $job_id = grab_array_var($inargs, 'job_id', 0); $hosts = grab_array_var($inargs, 'hosts', array()); $vcenter_host = grab_array_var($inargs, "vcenter_host", ""); $vcenter_port = intval(grab_array_var($inargs, "vcenter_port", 443)); $vcenter_no_ssl_verify = grab_array_var($inargs, "vcenter_no_ssl_verify", 1); $vcenter_vmname = grab_array_var($inargs, "vcenter_vmname", ""); $vcenter_username = grab_array_var($inargs, "vcenter_username", ""); $vcenter_password = grab_array_var($inargs, "vcenter_password", ""); $vmdisk_info = grab_array_var($inargs, "vmdisk_info", ""); $output = ' '; if (!empty($hosts)) { foreach ($hosts as $h) { $output .= ''; } } break; case CONFIGWIZARD_MODE_VALIDATESTAGE3DATA: break; case CONFIGWIZARD_MODE_GETFINALSTAGEHTML: // Get variables that were passed to us $ip_address = grab_array_var($inargs, 'ip_address'); $hostname = grab_array_var($inargs, 'hostname'); $port = grab_array_var($inargs, 'port'); $token = grab_array_var($inargs, 'token'); $services = grab_array_var($inargs, 'services', array()); if (empty($services)) { $services_serial = grab_array_var($inargs, "services_serial", ""); $services = unserialize(base64_decode($services_serial)); } $default_mem_units = grab_array_var($inargs, 'default_mem_units'); $os = grab_array_var($inargs, 'os', ''); $job_id = grab_array_var($inargs, 'job_id', 0); $hosts = grab_array_var($inargs, 'hosts', array()); $vcenter_host = grab_array_var($inargs, "vcenter_host", ""); $vcenter_port = intval(grab_array_var($inargs, "vcenter_port", 443)); $vcenter_no_ssl_verify = grab_array_var($inargs, "vcenter_no_ssl_verify", 1); $vcenter_vmname = grab_array_var($inargs, "vcenter_vmname", ""); $vcenter_username = grab_array_var($inargs, "vcenter_username", ""); $vcenter_password = grab_array_var($inargs, "vcenter_password", ""); $vmdisk_info = grab_array_var($inargs, "vmdisk_info", ""); $output = ' '; if (!empty($hosts)) { foreach ($hosts as $h) { $output .= ''; } } break; case CONFIGWIZARD_MODE_GETOBJECTS: $hostname = grab_array_var($inargs, "hostname", ""); $ip_address = grab_array_var($inargs, "ip_address", ""); $port = grab_array_var($inargs, "port", ""); $token = grab_array_var($inargs, "token", ""); $default_mem_units = grab_array_var($inargs, 'default_mem_units'); $services_serial = grab_array_var($inargs, "services_serial", ""); $services = unserialize(base64_decode($services_serial)); $os = grab_array_var($inargs, "os", ""); $hosts = grab_array_var($inargs, "hosts", array()); $job_id = grab_array_var($inargs, "job_id", 0); $vcenter_host = grab_array_var($inargs, "vcenter_host", ""); $vcenter_port = intval(grab_array_var($inargs, "vcenter_port", 443)); $vcenter_no_ssl_verify = grab_array_var($inargs, "vcenter_no_ssl_verify", 1); $vcenter_vmname = grab_array_var($inargs, "vcenter_vmname", ""); $vcenter_username = grab_array_var($inargs, "vcenter_username", ""); $vcenter_password = grab_array_var($inargs, "vcenter_password", ""); $vmdisk_info = unserialize(base64_decode(grab_array_var($inargs, "vmdisk_info", ""))); // Get job info and token if (!empty($job_id) && !empty($hosts)) { $job = deploy_get_job($job_id); $token = decrypt_data($job['ncpa_token']); } // Save data for later use in re-entrance $meta_arr = array(); $meta_arr["hostname"] = $hostname; $meta_arr["ip_address"] = $ip_address; $meta_arr["port"] = $port; $meta_arr["token"] = $token; $meta_arr["services"] = $services; $meta_arr["job_id"] = $job_id; $meta_arr["hosts"] = $hosts; save_configwizard_object_meta($wizard_name, $hostname, "", $meta_arr); // Escape values for check_command line if (function_exists('nagiosccm_replace_command_line')) { $token = nagiosccm_replace_command_line($token, '$'); } else { $token = str_replace('!', '\!', $token); } $objs = array(); if (empty($hosts)) { if (!host_exists($hostname)) { $obj = array( "type" => OBJECTTYPE_HOST, "use" => "xiwizard_ncpa_host", "host_name" => $hostname, "address" => $ip_address, "icon_image" => npca_configwizard_get_os_icon($os), "statusmap_image" => npca_configwizard_get_os_icon($os), "_xiwizard" => $wizard_name); if ($vcenter_host != "") { $obj["_vcenterhost"] = $vcenter_host; $obj["_vcenterport"] = $vcenter_port; $obj["_vcentervm"] = $vcenter_vmname; $obj["_vcenterskipssl"] = $vcenter_no_ssl_verify; } $objs[] = $obj; } } else { foreach ($hosts as $h) { if (!host_exists($h)) { $obj = array( "type" => OBJECTTYPE_HOST, "use" => "xiwizard_ncpa_host", "host_name" => $h, "address" => $h, "_xiwizard" => $wizard_name); if ($vcenter_host != "") { $obj["_vcenterhost"] = $vcenter_host; $obj["_vcenterport"] = $vcenter_port; $obj["_vcentervm"] = $vcenter_vmname; $obj["_vcenterskipssl"] = $vcenter_no_ssl_verify; } $objs[] = $obj; } } } // Common plugin opts $commonopts = "-t ".escapeshellarg($token)." "; if ($port) { $commonopts .= "-P ".intval($port)." "; } // If we don't already have an array of hosts, make it $hostnames = array($hostname); if (!empty($hosts)) { $hostnames = $hosts; } foreach ($hostnames as $hostname) { foreach ($services as $type => $args) { $pluginopts = ""; $pluginopts .= $commonopts; switch ($type) { case "cpu_usage": if (!array_key_exists('monitor', $args)) { break; } $pluginopts .= "-M cpu/percent"; if (!empty($args['warning'])) { $pluginopts .= " -w " . escapeshellarg($args["warning"]); } if (!empty($args['critical'])) { $pluginopts .= " -c " . escapeshellarg($args["critical"]); } if (!empty($args['average'])) { $pluginopts .= " -q 'aggregate=avg'"; } $objs[] = array( "type" => OBJECTTYPE_SERVICE, "host_name" => $hostname, "service_description" => "CPU Usage", "use" => "xiwizard_ncpa_service", "check_command" => "check_xi_ncpa!" . $pluginopts, "_xiwizard" => $wizard_name); break; case "users": if (!array_key_exists('monitor', $args)) { break; } $pluginopts .= "-M user/count"; if (!empty($args['warning'])) { $pluginopts .= " -w " . escapeshellarg($args["warning"]); } if (!empty($args['critical'])) { $pluginopts .= " -c " . escapeshellarg($args["critical"]); } $objs[] = array( "type" => OBJECTTYPE_SERVICE, "host_name" => $hostname, "service_description" => "User Count", "use" => "xiwizard_ncpa_service", "check_command" => "check_xi_ncpa!" . $pluginopts, "_xiwizard" => $wizard_name); break; case "memory_usage": if (!array_key_exists('monitor', $args)) { break; } $pluginopts .= "-M memory/virtual"; if (!empty($default_mem_units)) { $pluginopts .= " -u " . escapeshellarg($default_mem_units); } if (!empty($args['warning'])) { $pluginopts .= " -w " . escapeshellarg($args["warning"]); } if (!empty($args['critical'])) { $pluginopts .= " -c " . escapeshellarg($args["critical"]); } $objs[] = array( "type" => OBJECTTYPE_SERVICE, "host_name" => $hostname, "service_description" => "Memory Usage", "use" => "xiwizard_ncpa_service", "check_command" => "check_xi_ncpa!" . $pluginopts, "_xiwizard" => $wizard_name); break; case "swap_usage": if (!array_key_exists('monitor', $args)) { break; } $pluginopts .= "-M memory/swap"; if (!empty($default_mem_units)) { $pluginopts .= " -u " . escapeshellarg($default_mem_units); } if (!empty($args['warning'])) { $pluginopts .= " -w " . escapeshellarg($args["warning"]); } if (!empty($args['critical'])) { $pluginopts .= " -c " . escapeshellarg($args["critical"]); } $objs[] = array( "type" => OBJECTTYPE_SERVICE, "host_name" => $hostname, "service_description" => "Swap Usage", "use" => "xiwizard_ncpa_service", "check_command" => "check_xi_ncpa!" . $pluginopts, "_xiwizard" => $wizard_name); break; case "disk": foreach ($args as $id => $metrics) { if (!array_key_exists('monitor', $metrics)) { continue; } // Ensure we are using the right name/title for the disk API (and verify it has | instead of / or \) $title = $metrics['name']; if (isset($metrics['title'])) { $title = $metrics['title']; } $title = str_replace(array('\\', '/'), '|', $title); $disk = "disk/logical/{$title}"; $theseopts = "{$pluginopts} -M " . escapeshellarg($disk); if (!empty($metrics["warning"])) { $theseopts .= " -w " . escapeshellarg($metrics["warning"]); } if (!empty($metrics["critical"])) { $theseopts .= " -c " . escapeshellarg($metrics["critical"]); } // Make sure back slash doesn't escape service description line $service_name = str_replace('\\', '/', $metrics["name"]); $obj = array( "type" => OBJECTTYPE_SERVICE, "host_name" => $hostname, "service_description" => "Disk Usage on " . $service_name, "use" => "xiwizard_ncpa_service", "check_command" => "check_xi_ncpa!" . $theseopts, "_xiwizard" => $wizard_name); if ($vcenter_host != "" && $metrics["vmdisk"] != "none") { foreach ($vmdisk_info as $vmdisk) { if ($vmdisk["uuid"] == $metrics["vmdisk"]) { $fullpath = $vmdisk["fullpath"]; if (preg_match('/\[(.*)\] (.*)/', $fullpath, $matches)) { $obj["_vcenterdisk"] = $metrics["vmdisk"]; $obj["_vcenterdatastore"] = $matches[1]; $obj["_vcenterfilename"] = $matches[2]; $obj["event_handler_enabled"] = 1; if (strpos($vcenter_host, "vegas") !== false) { $obj["event_handler"] = "check_las_vegas"; } else { $obj["event_handler"] = "check_studio_city"; } } } } } $objs[] = $obj; } break; case "interface": foreach ($args as $id => $metrics) { if (!array_key_exists('monitor', $metrics) || empty($metrics['name'])) { continue; } $title = $metrics['name']; $theseopts = "{$pluginopts} -M 'interface/{$title}/bytes_sent' -d -u M"; if (!empty($metrics["warning"])) { $theseopts .= " -w " . escapeshellarg($metrics["warning"]); } if (!empty($metrics["critical"])) { $theseopts .= " -c " . escapeshellarg($metrics["critical"]); } $objs[] = array( "type" => OBJECTTYPE_SERVICE, "host_name" => $hostname, "service_description" => "{$title} Bandwidth - Outbound", "use" => "xiwizard_ncpa_service", "check_command" => "check_xi_ncpa!" . $theseopts, "_xiwizard" => $wizard_name); $theseopts = "{$pluginopts} -M 'interface/{$title}/bytes_recv' -d -u M"; if (!empty($metrics["warning"])) { $theseopts .= " -w " . escapeshellarg($metrics["warning"]); } if (!empty($metrics["critical"])) { $theseopts .= " -c " . escapeshellarg($metrics["critical"]); } $objs[] = array( "type" => OBJECTTYPE_SERVICE, "host_name" => $hostname, "service_description" => "{$title} Bandwidth - Inbound", "use" => "xiwizard_ncpa_service", "check_command" => "check_xi_ncpa!" . $theseopts, "_xiwizard" => $wizard_name); } break; case "services": foreach ($args as $i => $service) { if (!array_key_exists('monitor', $service) || empty($service['name']) || empty($service['desc'])) { continue; } $query = "service=" . str_replace('$', '$$', $service["name"]) . ",status=" . $service["state"]; $theseopts = "{$pluginopts} -M 'services' -q " . escapeshellarg($query); $objs[] = array( "type" => OBJECTTYPE_SERVICE, "host_name" => $hostname, "service_description" => $service["desc"], "use" => "xiwizard_ncpa_service", "check_command" => "check_xi_ncpa!" . $theseopts, "_xiwizard" => $wizard_name); } break; case "process": foreach ($args as $i => $metrics) { if (!array_key_exists('monitor', $metrics) || empty($metrics['desc'])) { continue; } $proc_name = $metrics['name']; $theseopts = "{$pluginopts} -M 'processes' -q 'name={$proc_name}'"; if (!empty($metrics["warning"])) { $theseopts .= " -w " . escapeshellarg($metrics["warning"]); } if (!empty($metrics["critical"])) { $theseopts .= " -c " . escapeshellarg($metrics["critical"]); } $objs[] = array( "type" => OBJECTTYPE_SERVICE, "host_name" => $hostname, "service_description" => $metrics['desc'], "use" => "xiwizard_ncpa_service", "check_command" => "check_xi_ncpa!" . $theseopts, "_xiwizard" => $wizard_name); } break; case 'counters': foreach ($args as $i => $counter) { if (!array_key_exists('monitor', $counter) || empty($counter['desc'])) { continue; } $theseopts = "{$pluginopts} -M ". escapeshellarg("windowscounters/".str_replace('\\', '/', $counter['name'])); if (!empty($counter["warning"])) { $theseopts .= " -w " . escapeshellarg($counter["warning"]); } if (!empty($counter["critical"])) { $theseopts .= " -c " . escapeshellarg($counter["critical"]); } if (!empty($count["sleep"])) { $theseopts .= " -q 'sleep=" . intval($counter["sleep"]) . "'"; } $objs[] = array( "type" => OBJECTTYPE_SERVICE, "host_name" => $hostname, "service_description" => $counter['desc'], "use" => "xiwizard_ncpa_service", "check_command" => "check_xi_ncpa!" . $theseopts, "_xiwizard" => $wizard_name); } break; case "plugins": foreach ($args as $i => $plugin) { if (!array_key_exists('monitor', $plugin) || empty($plugin['desc'])) { continue; } $theseopts = "{$pluginopts} -M " . escapeshellarg("plugins/".$plugin['name']); if (!empty($plugin['args'])) { $theseopts .= " -q " . escapeshellarg("args=".$plugin['args']); } $objs[] = array( "type" => OBJECTTYPE_SERVICE, "host_name" => $hostname, "service_description" => $plugin['desc'], "use" => "xiwizard_ncpa_service", "check_command" => "check_xi_ncpa!" . $theseopts, "_xiwizard" => $wizard_name); } break; default: break; } } } // Return the object definitions to the wizard $outargs[CONFIGWIZARD_NAGIOS_OBJECTS] = $objs; break; default: break; } return $output; } /** * Get operating system icon based on OS name * * @param string $os Operating system * @return string Icon file */ function ncpa_vmware_configwizard_get_os_icon($os) { $icon = "ncpa.png"; $os = strtolower($os); switch ($os) { case "rhel": $icon = "redhat.png"; break; case "fedora": $icon = "fedora.png"; break; case "centos": $icon = "centos.png"; break; case "oracle": $icon = "oracle-linux.gif"; break; case "ubuntu": $icon = "ubuntu.png"; break; case "debian": $icon = "debian.png"; break; case "sles": $icon = "suse_enterprise.png"; break; case "suse": $icon = "opensuse.png"; break; case "windows": $icon = "win_server.png"; break; case "aix": $icon = "aix.png"; break; case "sol": $icon = "solaris.png"; break; case "osx": $icon = "osx.png"; break; } return $icon; } /** * Send a request to the NCPA API and get the returned JSON as an array * * @param string $endpoint API endpoint * @param string $api_url API URL * @param string $token Security token * @param boolean $no_ssl_verify If true, do not verify SSL certificate * @param array $params Optional HTTP parameters passed via the URL * @return array */ function ncpa_vmware_configwizard_get_api_data($endpoint, $api_url, $token, $no_ssl_verify, $params = array()) { // Remove SSL verification or not $context = array("ssl" => array("verify_peer" => true, "verify_peer_name" => true)); if ($no_ssl_verify) { $context['ssl']['verify_peer'] = false; $context['ssl']['verify_peer_name'] = false; } // Setup API url $params['token'] = $token; $full_api_url = $api_url."/".$endpoint."?".http_build_query($params); // Do connection and get data $data = file_get_contents($full_api_url, false, stream_context_create($context)); $data = json_decode($data, true); if (array_key_exists('value', $data)) { $data = array_pop($data['value']); } else { $data = array_pop($data); } return $data; }