add(NagiosHostPeer::NAME, $_GET['q']."%", Criteria::LIKE);
$c->setIgnoreCase(true);
$results = NagiosHostPeer::doSelect($c);
break;
case 'hostgroup':
$c = new Criteria();
$c->add(NagiosHostgroupPeer::NAME, $_GET['q']."%", Criteria::LIKE);
$c->setIgnoreCase(true);
$results = NagiosHostgroupPeer::doSelect($c);
case 'service':
// Get the host
$c = new Criteria();
$c->add(NagiosHostPeer::NAME, $_GET['host']);
$c->setIgnoreCase(true);
$host = NagiosHostPeer::doSelectOne($c);
$returnObj = array();
if(!$host) {
$returnObj['error'] = "Host " . $_GET['host'] . " not found.";
print(json_encode($returnObj));
exit();
}
else {
$returnObj['services'] = array();
// Okay, let's get services.
$services = $host->getNagiosServices();
foreach($services as $service) {
if(!in_array($service->getDescription(), $returnObj['services']))
$returnObj['services'][] = $service->getDescription();
}
$inherited_services = $host->getInheritedServices();
foreach($inherited_services as $service) {
if(!in_array($service->getDescription(), $returnObj['services']))
$returnObj['services'][] = $service->getDescription();
}
if(count($returnObj['services']) == 0) {
$returnObj['error'] = "No services for that host.";
}
print(json_encode($returnObj));
exit();
}
}
foreach($results as $result) {
print($result->getName() . "\n");
}
exit();
}
// Data preparation
if(!isset($_GET['section']))
$_GET['section'] = 'general';
// If we're going to modify dependency data
if(isset($_GET['id'])) {
$dependency = NagiosDependencyPeer::retrieveByPK($_GET['id']);
if(!$dependency) {
header("Location: welcome.php");
}
}
// Action Handlers
if(isset($_GET['request'])) {
if($_GET['request'] == "delete" && $_GET['section'] == "targets") {
$target = NagiosDependencyTargetPeer::retrieveByPK($_GET['target_id']);
if(!$target) {
$error = "That target was not found.";
}
else if($target->getNagiosDependency()->getId() != $dependency->getId()) {
$error = "That target does not belong to this dependency.";
}
else {
// Okay, let's delete.
$target->delete();
$success = "Target deleted.";
}
}
}
if(isset($_POST['request'])) {
if($_POST['request'] == 'dependency_modify_general') {
// Field Error Checking
if(isset($_POST['dependency_manage']['inherits_parent'])) {
$dependency->setInheritsParent(true);
}
else {
$dependency->setInheritsParent(false);
}
if($_POST['dependency_manage']['dependency_period'] == '') {
$dependency->setDependencyPeriod(null);
}
else {
$dependency->setDependencyPeriod($_POST['dependency_manage']['dependency_period']);
}
// Execution criteria
if(isset($_POST['dependency_manage']['execution_failure_criteria_up'])) {
$dependency->setExecutionFailureCriteriaUp(true);
}
else {
$dependency->setExecutionFailureCriteriaUp(false);
}
if(isset($_POST['dependency_manage']['execution_failure_criteria_down'])) {
$dependency->setExecutionFailureCriteriaDown(true);
}
else {
$dependency->setExecutionFailureCriteriaDown(false);
}
if(isset($_POST['dependency_manage']['execution_failure_criteria_unreachable'])) {
$dependency->setExecutionFailureCriteriaUnreachable(true);
}
else {
$dependency->setExecutionFailureCriteriaUnreachable(false);
}
if(isset($_POST['dependency_manage']['execution_failure_criteria_pending'])) {
$dependency->setExecutionFailureCriteriaPending(true);
}
else {
$dependency->setExecutionFailureCriteriaPending(false);
}
if(isset($_POST['dependency_manage']['execution_failure_criteria_ok'])) {
$dependency->setExecutionFailureCriteriaOk(true);
}
else {
$dependency->setExecutionFailureCriteriaOk(false);
}
if(isset($_POST['dependency_manage']['execution_failure_criteria_warning'])) {
$dependency->setExecutionFailureCriteriaWarning(true);
}
else {
$dependency->setExecutionFailureCriteriaWarning(false);
}
if(isset($_POST['dependency_manage']['execution_failure_criteria_unknown'])) {
$dependency->setExecutionFailureCriteriaUnknown(true);
}
else {
$dependency->setExecutionFailureCriteriaUnknown(false);
}
if(isset($_POST['dependency_manage']['execution_failure_criteria_critical'])) {
$dependency->setExecutionFailureCriteriaCritical(true);
}
else {
$dependency->setExecutionFailureCriteriaCritical(false);
}
// Notification criteria
if(isset($_POST['dependency_manage']['notification_failure_criteria_up'])) {
$dependency->setNotificationFailureCriteriaUp(true);
}
else {
$dependency->setNotificationFailureCriteriaUp(false);
}
if(isset($_POST['dependency_manage']['notification_failure_criteria_down'])) {
$dependency->setNotificationFailureCriteriaDown(true);
}
else {
$dependency->setNotificationFailureCriteriaDown(false);
}
if(isset($_POST['dependency_manage']['notification_failure_criteria_unreachable'])) {
$dependency->setNotificationFailureCriteriaUnreachable(true);
}
else {
$dependency->setNotificationFailureCriteriaUnreachable(false);
}
if(isset($_POST['dependency_manage']['notification_failure_criteria_pending'])) {
$dependency->setNotificationFailureCriteriaPending(true);
}
else {
$dependency->setNotificationFailureCriteriaPending(false);
}
if(isset($_POST['dependency_manage']['notification_failure_criteria_ok'])) {
$dependency->setNotificationFailureCriteriaOk(true);
}
else {
$dependency->setNotificationFailureCriteriaOk(false);
}
if(isset($_POST['dependency_manage']['notification_failure_criteria_warning'])) {
$dependency->setNotificationFailureCriteriaWarning(true);
}
else {
$dependency->setNotificationFailureCriteriaWarning(false);
}
if(isset($_POST['dependency_manage']['notification_failure_criteria_unknown'])) {
$dependency->setNotificationFailureCriteriaUnknown(true);
}
else {
$dependency->setNotificationFailureCriteriaUnknown(false);
}
if(isset($_POST['dependency_manage']['notification_failure_criteria_critical'])) {
$dependency->setNotificationFailureCriteriaCritical(true);
}
else {
$dependency->setNotificationFailureCriteriaCritical(false);
}
$dependency->save();
$success = "Dependency modified.";
unset($_GET['edit']);
}
else if($_POST['request'] == 'add_target') {
$type = $dependency->getType();
if($type == "host" || $type == "hosttemplate" || $type == "hostgroup") {
if($_POST['typeselect'] == "host") {
// First find the host
$c = new Criteria();
$c->add(NagiosHostPeer::NAME, $_POST['name']);
$c->setIgnoreCase(true);
$tempHost = NagiosHostPeer::doSelectOne($c);
if(!$tempHost) {
$error = "The host specified by name " . $_POST['name'] . " was not found.";
}
else {
// Check for target existence
$c = new Criteria();
$c->add(NagiosDependencyTargetPeer::DEPENDENCY, $dependency->getId());
$c->add(NagiosDependencyTargetPeer::TARGET_HOST, $tempHost->getId());
$target = NagiosDependencyTargetPeer::doSelectOne($c);
if($target) {
$error = "That target already exists.";
}
else {
// Add the target.
$target = new NagiosDependencyTarget();
$target->setNagiosDependency($dependency);
$target->setNagiosHost($tempHost);
$target->save();
$success = "Created target.";
}
}
}
else if($_POST['typeselect'] == "hostgroup") {
// First find the hostgroup
$c = new Criteria();
$c->add(NagiosHostgroupPeer::NAME, $_POST['name']);
$c->setIgnoreCase(true);
$tempHostgroup = NagiosHostgroupPeer::doSelectOne($c);
if(!$tempHostgroup) {
$error = "The hostgroup specified by name " . $_POST['name'] . " was not found.";
}
else {
// Check for target existence
$c = new Criteria();
$c->add(NagiosDependencyTargetPeer::DEPENDENCY, $dependency->getId());
$c->add(NagiosDependencyTargetPeer::TARGET_HOSTGROUP, $tempHostgroup->getId());
$target = NagiosDependencyTargetPeer::doSelectOne($c);
if($target) {
$error = "That target already exists.";
}
else {
// Add the target.
$target = new NagiosDependencyTarget();
$target->setNagiosDependency($dependency);
$target->setNagiosHostgroup($tempHostgroup);
$target->save();
$success = "Created target.";
}
}
}
}
else {
// Get the host
$c = new Criteria();
$c->add(NagiosHostPeer::NAME, $_POST['hostname']);
$c->setIgnoreCase(true);
$host = NagiosHostPeer::doSelectOne($c);
if(!$host) {
$error = "The host specified by name " . $_POST['hostname'] . " was not found.";
}
else {
// Okay, let's find the service
$services = $host->getNagiosServices();
$found = false;
foreach($services as $service) {
if($service->getDescription() == $_POST['service_select']) {
// We found it! Regular service target.
// Check for existence
$c = new Criteria();
$c->add(NagiosDependencyTargetPeer::DEPENDENCY, $dependency->getId());
$c->add(NagiosDependencyTargetPeer::TARGET_HOST, $host->getId());
$c->add(NagiosDependencyTargetPeer::TARGET_SERVICE, $service->getId());
$target = NagiosDependencyTargetPeer::doSelectOne($c);
if($target) {
$error = "That target already exists.";
}
else {
$target = new NagiosDependencyTarget();
$target->setNagiosDependency($dependency);
$target->setNagiosHost($host);
$target->setNagiosService($service);
$target->save();
$success = "Created target.";
$found = true;
break;
}
}
}
if(!$found) {
// Check inherited services
$inheritedServices = $host->getInheritedServices();
foreach($inheritedServices as $service) {
if($service->getDescription() == $_POST['service_select']) {
// We found it!
// Check for existence
$c = new Criteria();
$c->add(NagiosDependencyTargetPeer::DEPENDENCY, $dependency->getId());
$c->add(NagiosDependencyTargetPeer::TARGET_HOST, $host->getId());
$c->add(NagiosDependencyTargetPeer::TARGET_SERVICE, $service->getId());
$target = NagiosDependencyTargetPeer::doSelectOne($c);
if($target) {
$error = "That target already exists.";
}
else {
$target = new NagiosDependencyTarget();
$target->setNagiosDependency($dependency);
$target->setNagiosHost($host);
$target->setNagiosService($service);
$target->save();
$success = "Created target.";
$found = true;
break;
}
}
}
}
}
}
}
}
$period_list = array();
$lilac->return_period_list($tempList);
$period_list[] = array("timeperiod_id" => '', "timeperiod_name" => 'Active Always');
foreach($tempList as $period) {
$period_list[] = array("timeperiod_id" => $period->getId(), "timeperiod_name" => $period->getName());
}
$title = '';
if($dependency->getNagiosService() || $dependency->getNagiosServiceTemplate()) {
$title .= "Service ";
if($dependency->getNagiosServiceTemplate()) {
$title .= "Template " . $dependency->getNagiosServiceTemplate()->getName() . "";
$sublink = "service_template.php?id=" . $dependency->getNagiosServiceTemplate()->getId();
$subText = "Return To Service Template " . $dependency->getNagiosServiceTemplate()->getName();
}
else {
$title .= "" . $dependency->getNagiosService()->getDescription() . " On ";
if($dependency->getNagiosService()->getNagiosHostTemplate()) {
$title .= " Host Template " . $dependency->getNagiosService()->getNagiosHostTemplate()->getName() . "";
}
else if($dependency->getNagiosService()->getNagiosHost()) {
$title .= "Host " . "" . $dependency->getNagiosService()->getNagiosHost()->getName() . "";
}
$sublink = "service.php?id=" . $dependency->getNagiosService()->getId();
$subText = "Return To Service " . $dependency->getNagiosService()->getDescription();
}
}
else {
if($dependency->getNagiosHostTemplate()) {
$title .= "Host Template " . $dependency->getNagiosHostTemplate()->getName() . "";
$sublink = "host_template.php?id=" . $dependency->getNagiosHostTemplate()->getId();
$subText = "Return To Host Template " . $dependency->getNagiosHostTemplate()->getName();
}
else if($dependency->getNagiosHost()) {
$title .= "Host " . $dependency->getNagiosHost()->getName() . "";
$sublink = "hosts.php?id=" . $dependency->getNagiosHost()->getId();
$subText = "Return To Host " . $dependency->getNagiosHost()->getName();
}
else if($dependency->getNagiosHostgroup()) {
$title .= "Hostgroup " . $dependency->getNagiosHostgroup()->getName() . "";
$sublink = "hostgroups.php?id=" . $dependency->getNagiosHostgroup()->getId();
$subText = "Return To Hostgroup " . $dependency->getNagiosHostgroup()->getName();
}
}
print_header("Dependency Editor for " . strip_tags($title));
?>
getName();
// Build subnav
$subnav = array(
'general' => 'General',
'targets' => 'Targets'
);
print_window_header($titlebar, "100%");
print_subnav($subnav, $_GET['section'], "section", $_SERVER['PHP_SELF'] . "?id=" . $_GET['id']);
if($_GET['section'] == 'general') {
if(!$dependency->getNagiosService())
$dependency_image = $path_config['image_root'] . "server.gif";
else
$dependency_image = $path_config['image_root'] . "services.gif";
?>
|
|
getNagiosDependencyTargets();
$numOfTargets = count($targets_list);
?>
|
Targets for this Dependency: |
[ Delete ] |
getType()) {
case 'host':
print("Host: " . $target->getNagiosHost()->getName());
break;
case 'hostgroup':
print("Hostgroup: " . $target->getNagiosHostgroup()->getName());
break;
case 'service':
print("Service: " . $target->getNagiosHost()->getName() . " - " . $target->getNagiosService()->getDescription());
break;
};?>
|
Add A Target:
getType();
if(in_array($type, array("host", "hosttemplate", "hostgroup"))) {
?>
Select either Host or Hostgroup from the Type dropdown, and begin typing the name of the host/hostgroup. Select the matched host/hostgroup you want to be dependent on and click on Add Target.
|