function handle_action_rdp($MAPCFG, $objId) { $host_name = $MAPCFG->getValue($objId, 'host_name'); $domain = $MAPCFG->getValue($objId, 'domain'); $username = $MAPCFG->getValue($objId, 'username'); // Get the host address! erm ... looks a little complicated... global $_BACKEND; $backendIds = $MAPCFG->getValue($objId, 'backend_id'); $OBJ = new NagVisHost($backendIds, $host_name); $OBJ->setConfiguration($MAPCFG->getMapObject($objId)); $OBJ->queueState(GET_STATE, DONT_GET_SINGLE_MEMBER_STATES); $_BACKEND->execute(); $OBJ->applyState(); $host_address = $OBJ->getStateAttr(ADDRESS); // Now generate the .rdp file for the user which is then (hopefully) handled // correctly by the users browser. header('Content-Type: application/rdp; charset=utf-8'); header('Content-Disposition: attachment; filename=' . $host_name . '.rdp'); echo 'full address:s:' . $host_address . "\n"; if ($domain) { echo 'domain:s:' . $domain . "\n"; } if ($username) { echo 'username:s:' . $username . "\n"; } }
function handle_action_win_ssh($MAPCFG, $objId) { $host_name = $MAPCFG->getValue($objId, 'host_name'); // Get the host address! erm ... looks a little complicated... global $_BACKEND; $backendIds = $MAPCFG->getValue($objId, 'backend_id'); $OBJ = new NagVisHost($backendIds, $host_name); $OBJ->setConfiguration($MAPCFG->getMapObject($objId)); $OBJ->queueState(GET_STATE, DONT_GET_SINGLE_MEMBER_STATES); $_BACKEND->execute(); $OBJ->applyState(); $host_address = $OBJ->getStateAttr(ADDRESS); // Now generate the .cmd file for the user which is then (hopefully) handled // correctly by the users browser. header('Content-Type: application/cmd; charset=utf-8'); header('Content-Disposition: attachment; filename=' . $host_name . '.cmd'); echo "@echo off\n"; echo "REM # This file has been generated by NagVis.\n"; echo "REM # \n"; echo "REM # Simply execute the file to connect to the host via SSH. We assume\n"; echo "REM # that you have putty installed and in your system path.\n"; echo "putty -ssh " . $host_address . " 22\n"; }
private function createHostObject($backendId, $name, $state, $config, $service_states) { $OBJ = new NagVisHost($backendId, $name); $OBJ->setState($state); // The services have to know how they should handle hard/soft // states. This is a little dirty but the simplest way to do this // until the hard/soft state handling has moved from backend to the // object classes. $OBJ->setConfiguration($config); // Put state counts to the object if ($service_states !== null) { $OBJ->addStateCounts($service_states); } // Fetch summary state and output $OBJ->fetchSummariesFromCounts(); return $OBJ; }
/** * PRIVATE fetchSummaryOutputFromCounts() * * Fetches the summary output from the object state counts * * @author Lars Michelsen <*****@*****.**> */ private function fetchSummaryOutputFromCounts() { if (NagVisHost::$langHostStateIs === null) { NagVisHost::$langHostStateIs = l('hostStateIs'); } // Write host state $this->sum[OUTPUT] = NagVisHost::$langHostStateIs . ' ' . state_str($this->state[STATE]) . '. '; // Only merge host state with service state when recognize_services is set // to 1 if ($this->recognize_services) { $iNumServices = 0; $arrServiceStates = array(); // Loop all major states if ($this->aStateCounts !== null) { foreach ($this->aStateCounts as $sState => $aSubstates) { if (is_host_state($sState)) { continue; } // Loop all substates (normal,ack,downtime,...) foreach ($aSubstates as $sSubState => $iCount) { // Found some objects with this state+substate if ($iCount > 0) { if (!isset($arrServiceStates[$sState])) { $arrServiceStates[$sState] = $iCount; $iNumServices += $iCount; } else { $arrServiceStates[$sState] += $iCount; $iNumServices += $iCount; } } } } } if ($iNumServices > 0) { if (NagVisHost::$langServices === null) { NagVisHost::$langServices = l('services'); } $this->mergeSummaryOutput($arrServiceStates, NagVisHost::$langServices); } else { $this->sum[OUTPUT] .= l('hostHasNoServices', 'HOST~' . $this->getName()); } } }