setStatusCode(AutodiscoveryJob::STATUS_STARTING); $autodiscoveryJob->save(); exec("php autodiscovery/autodiscover.php " . $autodiscoveryJob->getId() . " > /dev/null", $tempOutput, $retVal); if($retVal != 42) { $error = "Failed to run external autodiscovery script. Return value: " . $retVal . "
Error:"; foreach($tempOutput as $output) { $error .= $output . "
"; } } else { // No need to show //$success = "Restarted AutoDiscovery Job"; } } if(isset($_GET['delete'])) { // We want to delete the job! $autodiscoveryJob->delete(); unset($_GET['id']); unset($autodiscoveryJob); $success = "Removed Job and associated devices."; } } if(isset($_GET['deviceId'])) { // We want to review a specific device $device = AutodiscoveryDevicePeer::retrieveByPK($_GET['deviceId']); if(!$device) { header("Location: autodiscovery.php"); exit(); } if(isset($_GET['request']) && $_GET['request'] == 'recalc') { // We want to recalculate template matches $config = unserialize($autodiscoveryJob->getConfig()); $defaultTemplateId = $config->getVar("default_template"); if(!empty($defaultTemplateId)) { $defaultTemplate = NagiosHostTemplatePeer::retrieveByPK($defaultTemplateId); } if(empty($defaultTemplate)) { $defaultTemplate = null; } AutodiscoveryMatchMaker::match($device, $defaultTemplate); $success = "Recalculated Matching Templates."; } } if(isset($_GET['request']) && $_GET['request'] == 'status') { // We're our AJAX client wanting status information $result = array(); $autodiscoveryJob = AutodiscoveryJobPeer::retrieveByPK($_GET['id']); if(!$autodiscoveryJob) { $result['error'] = "Invalid job specified."; print(json_encode($result)); exit(); } // Okay, let's populate the status $result['start_time'] = $autodiscoveryJob->getStartTime(); $result['status_code'] = $autodiscoveryJob->getStatusCode(); $result['status_text'] = $autodiscoveryJob->getStatus(); $result['status_change_time'] = $autodiscoveryJob->getStatusChangeTime(); // Build elapsed time if(!in_array($autodiscoveryJob->getStatusCode(), array(AutoDiscoveryJob::STATUS_FAILED, AutoDiscoveryJob::STATUS_FINISHED))) { $target = time(); } else { $target = strtotime($result['status_change_time']); } $start = strtotime($result['start_time']); $total = $target - $start; $hours = (int)($total / 3600); $total = $total % 3600; $minutes = (int)($total / 60); $seconds = $total % 60; $result['elapsed_time'] = $hours . " Hours " . $minutes . " Minutes " . $seconds . " Seconds"; print(json_encode($result)); exit(); } if(isset($_GET['request']) && $_GET['request'] == 'fetch') { // We're our AJAX client wanting to get new log data $result = array(); $c = new Criteria(); $c->add(AutodiscoveryLogEntryPeer::JOB, $_GET['id']); $c->setLimit($_POST['rp']); $c->setOffset(isset($_POST['page']) ? ($_POST['page'] - 1) * $_POST['rp'] : 0); $c->addDescendingOrderByColumn(AutodiscoveryLogEntryPeer::ID); $entries = $autodiscoveryJob->getAutodiscoveryLogEntrys($c); foreach($entries as $entry) { $results['rows'][] = array('id' => $entry->getId(), 'cell' => array( $entry->getTime(), $entry->getReadableType($entry->getType()), $entry->getText())); } $c = new Criteria(); $c->add(AutodiscoveryLogEntryPeer::JOB, $autodiscoveryJob->getId()); $results['page'] = $_POST['page']; $results['total'] = AutodiscoveryLogEntryPeer::doCount($c); ?> setVar("targets", $_POST['target']); $config->setVar("nmap_binary", $_POST['nmap_binary']); $config->setVar("traceroute_enabled", (empty($_POST['traceroute_enabled'])) ? true : true); $config->setVar("default_template", $_POST['default_template']); $autodiscoveryJob = new AutodiscoveryJob(); $autodiscoveryJob->setName($_POST['job_name']); $autodiscoveryJob->setDescription($_POST['job_description']); $autodiscoveryJob->setCmd(AutodiscoveryJob::CMD_START); $autodiscoveryJob->setConfig(serialize($config)); $autodiscoveryJob->setStatus("Starting..."); $autodiscoveryJob->setStatusCode(AutodiscoveryJob::STATUS_STARTING); $autodiscoveryJob->save(); // Attempt to execute the external auto-discovery script, fork it, and love it. exec("php autodiscovery/autodiscover.php " . $autodiscoveryJob->getId() . " > /dev/null", $tempOutput, $retVal); if($retVal != 42) { $status_msg = "Failed to run external Autodiscovery script. Return value: " . $retVal . "
Error:"; foreach($tempOutput as $output) { $status_msg .= $output . "
"; } } } } } else if($_POST['request'] == "updateGeneral") { if(trim($_POST['name']) != '' && trim($_POST['description']) != '') { // Check to see first if a host or auto discovery device has that potential name $c = new Criteria(); $c->add(NagiosHostPeer::NAME, trim($_POST['name'])); $c->setIgnoreCase(true); $host = NagiosHostPeer::doSelectOne($c); if(!$host) { // Try a autodiscovery device? $c = new Criteria(); $c->add(AutodiscoveryDevicePeer::NAME, trim($_POST['name'])); $c->setIgnoreCase(true); $host = AutodiscoveryDevicePeer::doSelectOne($c); } if($host) { $error = "A host already exists with that name. Must choose a unique name."; } else { // Assign name and description $device->setName(trim($_POST['name'])); $device->setDescription(trim($_POST['description'])); $device->save(); $success = "Updated discovered device's information."; } } else { $error = "Name and Description cannot be blank."; } } else if($_POST['request'] == "assignTemplate") { $hostTemplate = NagiosHostTemplatePeer::retrieveByPK($_POST['template']); if(!$hostTemplate) { $error = "That template no longer exists."; } else { $device->setNagiosHostTemplate($hostTemplate); $device->save(); $success = "Template assigned."; } } else { // We want to process our device list! // First we check to see if there's any hosts now with the same name foreach($_POST['selectedDevices'] as $deviceId) { $device = AutodiscoveryDevicePeer::retrieveByPK($deviceId); if(!$device) { $error = "One of the devices provided no longer exists."; continue; } $c = new Criteria(); $c->add(NagiosHostPeer::NAME, $device->getName()); $c->setIgnoreCase(true); $host = NagiosHostPeer::doSelectOne($c); if(!$host) { $c = new Criteria(); $c->add(AutodiscoveryDevicePeer::NAME, $device->getName()); $c->setIgnoreCase(true); $host = AutodiscoveryDevicePeer::doSelectOne($c); if($host->getId() == $device->getId()) { unset($host); } } if(!empty($host)) { $error = "A host already exists with the name of " . $device->getName() . ". Change the device's name before importing."; } } if(empty($error)) { $totalSuccess = 0; // Okay, no errors, let's create our hosts! foreach($_POST['selectedDevices'] as $deviceId) { $device = AutodiscoveryDevicePeer::retrieveByPK($deviceId); $tempHost = new NagiosHost(); $tempHost->setAddress($device->getAddress()); $tempHost->setName($device->getName()); $tempHost->setAlias($device->getDescription()); $tempHost->save(); // Now assign a template, if wanted $template = $device->getNagiosHostTemplate(); if(!empty($template)) { $inheritance = new NagiosHostTemplateInheritance(); $inheritance->setNagiosHost($tempHost); $inheritance->setNagiosHostTemplateRelatedByTargetTemplate($template); $inheritance->save(); } // Now parent $parent = $device->getNagiosHost(); if(!empty($parent)) { $parentRelationship = new NagiosHostParent(); $parentRelationship->setNagiosHostRelatedByChildHost($tempHost); $parentRelationship->setNagiosHostRelatedByParentHost($parent); $parentRelationship->save(); } $totalSuccess++; $device->delete(); } $success = $totalSuccess . " Device(s) Imported."; } } } print_header("AutoDiscovery"); if(isset($autodiscoveryJob)) { ?> add(AutodiscoveryJobPeer::END_TIME, null); $autodiscoveryJobs = autodiscoveryJobPeer::doSelect($c); if($autodiscoveryJobs) { print_window_header("Jobs In Progress", "100%"); ?> There appears to be running autodiscovery jobs. There should only be one running. If there are multiple showing as running, you should cancel them or purge them. Click on a job to view it's progress and it's log.
Name Description Start Time Status Actions
getName();?> getDescription();?> getStartTime();?> getStatus();?> View Job Restart
To begin an auto-discovery of your configuration, an Auto Discovery Job must be defined. Configure your auto discovery job below. Once created, your auto discovery job will begin in the background. You will be able to check on the status of your job and view it's log as it continues running. You are advised to NOT edit anything in Lilac while your job is running.

Job Definition

Discovery Options

Enable Traceroute to Determine Parent Host

'None', 'value' => '' ); foreach($templates as $template) { $options[] = array( 'option' => $template->getName(), 'value' => $template->getId() ); } print_select("default_template", $options, "value" , "option", ''); ?>

Target Specification

Add Target
Provide an IP address or range of ip addresses in NMAP-accepted style. See Target Specification for examples.

getStats(); if($stats) { $stats = unserialize($stats); } print_window_header("Job Details", "100%"); ?> Job Name: getName();?>
getDescription();?>

Start Time: getStartTime();?>

getStatusCode(), array(AutodiscoveryJob::STATUS_FAILED, AutodiscoveryJob::STATUS_FINISHED) )) { ?> Elapsed Time: Unknown getStatusCode() == AutodiscoveryJob::STATUS_FAILED) { ?> Time of Failure: getStatusChangeTime();?> Time When Completed: getStatusChangeTime();?>
Current Status: getStatus();?>
getConfig()); ?> getStatusCode() != AutodiscoveryJob::STATUS_FINISHED ) { ?>style="display: none;">
Auto-Discovery Complete. Click to Continue To Reviewing Found Devices
Restart Job | Remove Job | Return To AutoDiscovery Menu
Return To Auto-Discovery Job
add(AutodiscoveryDevicePeer::JOB_ID, $autodiscoveryJob->getId()); $devices = AutodiscoveryDevicePeer::doSelect($c); if(empty($devices)) { ?>

No Devices Available For Import


Device(s) Available For Import


Address Name Description Parent Hostname Template Assigned Actions
getAddress();?> getName();?> getDescription();?> getNagiosHost(); if(empty($parent)) { ?>Top-LevelgetName()); } ?> getHostname();?> getHostTemplate()) { ?>None AssignedgetHostTemplate()); if(!empty($hostTemplate)) { print($hostTemplate->getName()); } else { print("Template Not Found"); } } ?> Modify Details
Check All / Un-Check All With Selected:
[ Return To Device List ]

General Information

Address Name Description Parent Hostname OS Family OS Generation OS Vendor Template Assigned
getAddress(); ?> getName(); ?> getDescription(); ?> getNagiosHost(); if(empty($parent)) { ?>Top-LevelgetName()); } ?> getHostname(); ?> getOsfamily(); ?> getOsgen(); ?> getOsvendor(); ?> getHostTemplate()) { ?>None AssignedgetHostTemplate()); if(!empty($hostTemplate)) { print($hostTemplate->getName()); } else { print("Template Not Found"); } } ?>

Update General Information

Name: Description:

Change Template Assignment

getTemplateMatches(); $options = array(); $options[] = array( 'option' => 'None', 'value' => '' ); $searchArray = array(); foreach($matchedTemplates as $match) { $options[] = array( 'option' => $match->getNagiosHostTemplate()->getName() . " - " . $match->getPercent() . "%", 'value' => $match->getNagiosHostTemplate()->getId() ); $searchArray[] = $match->getNagiosHostTemplate()->getId(); } // Add the rest of the templates $templates = NagiosHostTemplatePeer::doSelect(new Criteria()); foreach($templates as $template) { if(!in_array($template->getId(), $searchArray)) { $options[] = array( 'option' => $template->getName() . " - n/a", 'value' => $template->getId() ); } } print_select("template", $options, "value", "option", $device->getHostTemplate()); ?> [ Recalculate Template Matches ]


add(AutodiscoveryDeviceServicePeer::DEVICE_ID, $device->getId()); $services = AutodiscoveryDeviceServicePeer::doSelect($c); if(empty($services)) { ?>

No Services Were Found On This Device

Found Service(s)

>

getName();?> on port getProtocol();?>/getPort(); ?>

Product: getProduct(); ?>
Version: getVersion(); ?>
Extra Information: getExtraInfo(); ?>