From: opensides Date: Sun, 25 Sep 2005 16:30:38 +0000 (+0000) Subject: new version of nagios plugin X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a2843007a8b103b9a6a215d8f7c0f7b616cc9c32;p=gosa.git new version of nagios plugin removal of ugly code ;-( git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@1410 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/plugins/personal/nagios/class_nagiosAccount.inc b/plugins/personal/nagios/class_nagiosAccount.inc index 0d668cab0..a6ebedf56 100644 --- a/plugins/personal/nagios/class_nagiosAccount.inc +++ b/plugins/personal/nagios/class_nagiosAccount.inc @@ -1,8 +1,16 @@ + \author Benoit Mortier + \version 1.00 + \date 25.09.2005 + + This class provides the functionality to read and write all attributes + relevant for nagiosAccount from/to the LDAP. It does syntax checking + and displays the formulars required. + */ + class nagiosAccount extends plugin { /* Definitions */ @@ -11,125 +19,112 @@ class nagiosAccount extends plugin /* CLI vars */ var $cli_summary= "Manage users nagios account"; - var $cli_description= "Some longer text\nfor help"; + var $cli_description= "Manage Account and autorization\nfor Nagios"; var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser"); - - /* These contain attributes to be loaded. We're not doing an LDAP plugin currently, so we don't - care... */ - var $attributes= array("NagiosAlias","NagiosPager","NagiosMail","HostNotificationPeriod","ServiceNotificationPeriod","HostNotificationCommands","ServiceNotificationCommands", - "HostNotificationOptions", - "ServiceNotificationOptions", - "HostNotificationPeriod", - "ServiceNotificationPeriod", - "AuthorizedAllHosts", - "AuthorizedAllServices", - "AuthorizedSystemCommands", - "AuthorizedAllHostCommands", - "AuthorizedAllServiceCommands", - "AuthorizedConfigurationInformation", - "AuthorizedSystemInformation"); + + /* plugin specific values */ + var $NagiosAlias= ""; + var $NagiosPager= ""; + var $NagiosMail= ""; + var $HostNotificationPeriod= ""; + var $ServiceNotitificationPeriod= ""; + var $HostNotificationCommands= ""; + var $ServiceNotificationCommands= ""; + var $HostNotitificationOptions= ""; + var $ServiceNotificationOptions= ""; + var $HostNotificationPeriod= ""; + var $ServiceNotificationPeriod= ""; + + var $AuthorizedAllHosts= ""; + var $AuthorizedAllServices= ""; + var $AuthorizedSystemCommands= ""; + var $AuthorizedAllHostCommands= ""; + var $AuthorizedAllServiceCommands= ""; + var $AuthorizedConfigurationInformation= ""; + var $AuthorizedSystemInformation= ""; + + /* attribute list for save action */ + + var $attributes= array("NagiosAlias", "NagiosPager", "NagiosMail", "HostNotificationPeriod", + "ServiceNotificationPeriod", "HostNotificationCommands", "ServiceNotificationCommands", + "HostNotificationOptions", "ServiceNotificationOptions", "HostNotificationPeriod", + "ServiceNotificationPeriod", "AuthorizedAllHosts", "AuthorizedAllServices", + "AuthorizedSystemCommands", "AuthorizedAllHostCommands", "AuthorizedAllServiceCommands", + "AuthorizedConfigurationInformation", "AuthorizedSystemInformation"); + var $objectclasses= array("nagiosContact"); - /* The constructor just saves a copy of the config. You may add what ever you need. */ + /* constructor, if 'dn' is set, the node loads the given + 'dn' from LDAP */ function nagiosAccount ($config, $dn= NULL) { - /* Include config object */ - $this->config= $config; + /* Configuration is fine, allways */ + $this->config= $config; + plugin::plugin ($config, $dn); - $this->initially_was_account= $this->is_account; -} - /* Execute is the function all plugins need. It fills the plugin with life and produces the output. */ + /* Save initial account state */ + $this->initially_was_account= $this->is_account; + } + function execute() { - $display= ""; - /* Use the smarty templating engine here... */ - $smarty= get_smarty(); - - //echo "
";print_r($_POST);echo "
"; - /* Do we need to flip is_account state? */ - if (isset($_POST['modify_state'])){ - $this->is_account= !$this->is_account; - } - /* Do we represent a valid account? */ - if (!$this->is_account && $this->parent == NULL){ - $display= "\"\"src=\"images/stop.png\" ". - _("This account has no nagios extensions.").""; - $display.= back_to_main(); - return ($display); - } - /* Load attributes */ - foreach($this->attributes as $val){ - $smarty->assign("$val", $this->$val); - $smarty->assign($val."ACL", chkacl($this->acl, "$val")); - } - - if ($this->is_account){ - $smarty->assign("nagiosAuth","checked"); - $smarty->assign("nagiosContact","checked"); - } - - /* Show tab dialog headers */ - if ($this->parent != NULL){ - if ($this->is_account){ - $display= $this->show_header(_("Remove nagios account"), - _("This account has nagios features enabled. You can disable them by clicking below.")); - } else { - $display= $this->show_header(_("Create nagios account"), _("This account has nagios features disabled. You can enable them by clicking below.")); - return($display); - } - } + /* Load templating engine */ + $smarty= get_smarty(); + $display= ""; + + /* Do we need to flip is_account state? */ + if (isset($_POST['modify_state'])){ + $this->is_account= !$this->is_account; + } + + /* Do we represent a valid account? */ + if (!$this->is_account && $this->parent == NULL){ + $display= "\"\"src=\"images/stop.png\" ". + _("This account has no nagios extensions.").""; + + $display.= back_to_main(); + return ($display); + } + + /* Show tab dialog headers */ + if ($this->parent != NULL){ + if ($this->is_account){ + $display= $this->show_header(_("Remove nagios account"), + _("This account has nagios features enabled. You can disable them by clicking below.")); + } else { + $display= $this->show_header(_("Create nagios account"), _("This account has nagios features disabled. You can enable them by clicking below.")); + return($display); + } + } $display.= $smarty->fetch (get_template_path('nagios.tpl', TRUE, dirname(__FILE__))); - //echo "
";print_r($_POST);echo "
"; - return ($display); + return ($display); } - /* Save to LDAP */ -function save() -{ - /* Load uid and gid of this 'dn' */ - $ldap= $this->config->get_ldap_link(); - $ldap->cat($this->dn); - $tmp= $ldap->fetch(); - - plugin::save(); - - //nagiosContact - //ugly code but i will correct this after :) - - if(isset($_POST['NagiosAlias']))$this->attrs['NagiosAlias']=$_POST['NagiosAlias']; - if(isset($_POST['NagiosPager']))$this->attrs['NagiosAlias']=$_POST['NagiosAlias']; - if(isset($_POST['NagiosMail']))$this->attrs['NagiosMail']=$_POST['NagiosMail']; - if(isset($_POST['ServiceNotificationPeriod']))$this->attrs['ServiceNotificationPeriod']=$_POST['ServiceNotificationPeriod']; - if(isset($_POST['HostNotificationPeriod']))$this->attrs['HostNotificationPeriod']=$_POST['HostNotificationPeriod']; - if(isset($_POST['ServiceNotificationOptions']))$this->attrs['ServiceNotificationOptions']=$_POST['ServiceNotificationOptions']; - if(isset($_POST['HostNotificationOptions']))$this->attrs['HostNotificationOptions']=$_POST['HostNotificationOptions']; - if(isset($_POST['ServiceNotificationCommands']))$this->attrs['ServiceNotificationCommands']=$_POST['ServiceNotificationCommands']; - if(isset($_POST['HostNotificationCommands']))$this->attrs['HostNotificationCommands']=$_POST['HostNotificationCommands']; - - //nagiosAuth - if(isset($_POST['AuthorizedSystemInformation']))$this->attrs['AuthorizedSystemInformation']="checked";else $this->attrs['AuthorizedSystemInformation']="unchecked"; - if(isset($_POST['AuthorizedConfigurationInformation']))$this->attrs['AuthorizedConfigurationInformation']="checked";else $this->attrs['AuthorizedConfigurationInformation']="unchecked"; - if(isset($_POST['AuthorizedSystemCommands']))$this->attrs['AuthorizedSystemCommands']="checked";else $this->attrs['AuthorizedSystemCommands']="unchecked"; - if(isset($_POST['AuthorizedAllServices']))$this->attrs['AuthorizedAllServices']="checked";else $this->attrs['AuthorizedAllServices']="unchecked"; - if(isset($_POST['AuthorizedAllHosts']))$this->attrs['AuthorizedAllHosts']="checked";else $this->attrs['AuthorizedAllHosts']="unchecked"; - if(isset($_POST['AuthorizedAllServiceCommands']))$this->attrs['AuthorizedAllServiceCommands']="checked";else $this->attrs['AuthorizedAllServiceCommands']="unchecked"; - if(isset($_POST['AuthorizedAllHostCommands']))$this->attrs['AuthorizedAllHostCommands']="checked";else $this->attrs['AuthorizedAllHostCommands']="unchecked"; - - /* Write back to ldap */ - $ldap->cd($this->dn); - $ldap->modify($this->attrs); - show_ldap_error($ldap->get_error()); + + /* Save to LDAP */ + function save() + { + $ldap= $this->config->get_ldap_link(); + + /* Call parents save to prepare $this->attrs */ + plugin::save(); + + + /* Write back to ldap */ + $ldap->cd($this->dn); + $ldap->modify($this->attrs); + show_ldap_error($ldap->get_error()); - /* Optionally execute a command after we're done */ - if ($this->initially_was_account == $this->is_account){ - if ($this->is_modified){ - $this->handle_post_events("modify"); - } - } else { - $this->handle_post_events("add"); - } + /* Optionally execute a command after we're done */ + if ($this->initially_was_account == $this->is_account){ + if ($this->is_modified){ + $this->handle_post_events("modify"); + } + } else { + $this->handle_post_events("add"); + } -} + } function save_object() { @@ -162,5 +157,9 @@ function remove_from_parent() /* Optionally execute a command after we're done */ $this->handle_post_events('remove'); } + } -?> \ No newline at end of file + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: + +?> diff --git a/plugins/personal/nagios/nagios.tpl b/plugins/personal/nagios/nagios.tpl index 1ffb10ecf..2b51f15f5 100644 --- a/plugins/personal/nagios/nagios.tpl +++ b/plugins/personal/nagios/nagios.tpl @@ -40,3 +40,12 @@ authorized_for_all_host_commands
+ + + + +