예제 #1
0
 public function import()
 {
     $job = $this->getEngine()->getJob();
     $config = $this->getEngine()->getConfig();
     $cgiCfg = new NagiosCgiConfiguration();
     $segment = $this->getSegment();
     $values = $segment->getValues();
     $fileName = $segment->getFilename();
     foreach ($values as $key => $entries) {
         if (preg_match("/^authorized_for/i", $key)) {
             // We need to pass the entire value over.
             // Collect the entries
             $value = array();
             foreach ($entries as $entry) {
                 $value[] = $entry['value'];
             }
             $value = implode(",", $value);
             if (!method_exists($cgiCfg, $this->fieldMethods[$key])) {
                 $job->addError("Method " . $this->fieldMethods[$key] . " does not exist for variable: " . $key . " on line " . $entries[0]['line'] . " in file " . $fileName);
                 if (!$config->getVar('continue_error')) {
                     return false;
                 }
             } else {
                 call_user_method($this->fieldMethods[$key], $cgiCfg, $value);
             }
             continue;
         }
         foreach ($entries as $entry) {
             $value = $entry['value'];
             $lineNum = $entry['line'];
             if (key_exists($key, $this->fieldMethods) && $this->fieldMethods[$key] != '') {
                 // Okay, let's check that the method DOES exist
                 if (!method_exists($cgiCfg, $this->fieldMethods[$key])) {
                     $job->addError("Method " . $this->fieldMethods[$key] . " does not exist for variable: " . $key . " on line " . $lineNum . " in file " . $fileName);
                     if (!$config->getVar('continue_error')) {
                         return false;
                     }
                 } else {
                     call_user_method($this->fieldMethods[$key], $cgiCfg, $value);
                 }
             }
         }
     }
     // If we got here, it's safe to delete the existing main config and save the new one
     $oldConfig = NagiosCgiConfigurationPeer::doSelectOne(new Criteria());
     if ($oldConfig) {
         $oldConfig->clearAllReferences(true);
         $oldConfig->delete();
     }
     $cgiCfg->save();
     $cgiCfg->clearAllReferences(true);
     $job->addNotice("NagiosCgiImporter finished importing cgi configuration.");
     return true;
 }
예제 #2
0
 public function export()
 {
     // Grab our export job
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("NagiosCgiExporter attempting to export cgi configuration.");
     // Grab our cgi config
     $cgiConfig = NagiosCgiConfigurationPeer::doSelectOne(new Criteria());
     if (!$cgiConfig) {
         $job->addError("Unable to get CGI Configuration object.  Your Lilac database is corrupt.");
         return false;
     }
     $finalArray = array();
     $values = $cgiConfig->toArray(BasePeer::TYPE_FIELDNAME);
     foreach ($values as $key => $value) {
         if ($key == 'id') {
             continue;
         }
         if ($value === null) {
             continue;
         }
         if ($value === false) {
             $value = '0';
         }
         $finalArray[$key] = $value;
     }
     // get our main config
     $mainConfig = NagiosMainConfigurationPeer::doSelectOne(new Criteria());
     $configdir = $mainConfig->getConfigDir();
     $finalArray['main_config_file'] = $configdir . "/nagios.cfg";
     $fp = $this->getOutputFile();
     fputs($fp, "# Written by NagiosCgiExporter from " . LILAC_NAME . " " . LILAC_VERSION . " on " . date("F j, Y, g:i a") . "\n\n");
     foreach ($finalArray as $key => $val) {
         fputs($fp, $key . "=" . $val . "\n");
     }
     /*    Added by Romain Dessort (Evolix) on 08/02/2011:
      *
      *  nagios_check_command directive is required by Nagios, but
      *  Lilac does not allow to change this parameter in the web
      *  interface. I set it here.
      */
     fputs($fp, "nagios_check_command=/usr/lib/nagios/plugins/check_nagios /var/cache/nagios3/status.dat 5 '/usr/sbin/nagios3'\n");
     $job->addNotice("NagiosCgiExporter complete.");
     return true;
 }
예제 #3
0
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityCgiImporter beginning to import CGI Configuration.");
     // Cgi configuration
     $res = $this->dbConn->query("SELECT * FROM nagios_cgi");
     // Fruity has just one record in the resources, if we get it, import
     // it.
     $row = $res->fetch(PDO::FETCH_ASSOC);
     // Get our resources obj.
     $cgiConfig = NagiosCgiConfigurationPeer::doSelectOne(new Criteria());
     if (!$cgiConfig) {
         $cgiConfig = new NagiosCgiConfiguration();
         $cgiConfig->save();
     }
     foreach ($row as $key => $val) {
         unset($name);
         if ($key == "id" || $key == "show_context_help" || $key == "nagios_check_command") {
             continue;
         }
         // Iterate through and, if we have a valid key, we set it to
         // the NagiosResource obj.
         try {
             $name = NagiosCgiConfigurationPeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
         } catch (Exception $e) {
             $job->addNotice("CGI Configuration Importer: Was unable to store unsupported value: " . $key);
         }
         if (!empty($name)) {
             $method = "set" . $name;
             $cgiConfig->{$method}($val);
         }
     }
     $cgiConfig->save();
     // Save resources configuration
     $job->addNotice("FruityCgiImporter finished importing CGI Configuration.");
 }
예제 #4
0
파일: cgi.php 프로젝트: Evolix/lilac
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
/*
Lilac Index Page, Displays Menu, and Statistics
*/
include_once 'includes/config.inc';
$cgiConfig = NagiosCgiConfigurationPeer::doSelectOne(new Criteria());
if (!$cgiConfig) {
    $cgiConfig = new NagiosCgiConfiguration();
    $cgiConfig->save();
}
if (isset($_POST['request'])) {
    if ($_POST['request'] == 'update') {
        if (isset($_POST['cgi_config']['physical_html_path'])) {
            $cgiConfig->setPhysicalHtmlPath($_POST['cgi_config']['physical_html_path']);
        }
        if (isset($_POST['cgi_config']['url_html_path'])) {
            $cgiConfig->setUrlHtmlPath($_POST['cgi_config']['url_html_path']);
        }
        if (isset($_POST['cgi_config']['use_authentication'])) {
            $cgiConfig->setUseAuthentication($_POST['cgi_config']['use_authentication']);
        }
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(NagiosCgiConfigurationPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(NagiosCgiConfigurationPeer::DATABASE_NAME);
         $criteria->add(NagiosCgiConfigurationPeer::ID, $pks, Criteria::IN);
         $objs = NagiosCgiConfigurationPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
예제 #6
0
 public function import()
 {
     $job = $this->getJob();
     $job->addNotice("FruityImportEngine beginning import...");
     $config = $this->getConfig();
     $job->addNotice("Removing existing Nagios objects.");
     NagiosTimeperiodPeer::doDeleteAll();
     NagiosCommandPeer::doDeleteAll();
     NagiosContactPeer::doDeleteAll();
     NagiosContactGroupPeer::doDeleteAll();
     NagiosHostTemplatePeer::doDeleteAll();
     NagiosHostPeer::doDeleteAll();
     NagiosHostgroupPeer::doDeleteAll();
     NagiosServiceGroupPeer::doDeleteAll();
     NagiosServiceTemplatePeer::doDeleteAll();
     NagiosServicePeer::doDeleteAll();
     NagiosDependencyPeer::doDeleteAll();
     NagiosDependencyTargetPeer::doDeleteAll();
     NagiosEscalationPeer::doDeleteAll();
     NagiosBrokerModulePeer::doDeleteAll();
     NagiosMainConfigurationPeer::doDeleteAll();
     NagiosCgiConfigurationPeer::doDeleteAll();
     $importer = new FruityResourceImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityCgiImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityCommandImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityTimeperiodImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityContactImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityServiceGroupImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityServiceTemplateImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityHostTemplateImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityHostGroupImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityHostImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityServiceImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityDependencyImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityEscalationImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityMainImporter($this, $this->dbConn);
     $importer->import();
     $job->addNotice("FruityImportEngine completed job.");
     return true;
 }
예제 #7
0
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = NagiosCgiConfigurationPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setPhysicalHtmlPath($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setUrlHtmlPath($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setUseAuthentication($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setDefaultUserName($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setAuthorizedForSystemInformation($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setAuthorizedForSystemCommands($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setAuthorizedForConfigurationInformation($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setAuthorizedForAllHosts($arr[$keys[8]]);
     }
     if (array_key_exists($keys[9], $arr)) {
         $this->setAuthorizedForAllHostCommands($arr[$keys[9]]);
     }
     if (array_key_exists($keys[10], $arr)) {
         $this->setAuthorizedForAllServices($arr[$keys[10]]);
     }
     if (array_key_exists($keys[11], $arr)) {
         $this->setAuthorizedForAllServiceCommands($arr[$keys[11]]);
     }
     if (array_key_exists($keys[12], $arr)) {
         $this->setLockAuthorNames($arr[$keys[12]]);
     }
     if (array_key_exists($keys[13], $arr)) {
         $this->setStatusmapBackgroundImage($arr[$keys[13]]);
     }
     if (array_key_exists($keys[14], $arr)) {
         $this->setDefaultStatusmapLayout($arr[$keys[14]]);
     }
     if (array_key_exists($keys[15], $arr)) {
         $this->setStatuswrlInclude($arr[$keys[15]]);
     }
     if (array_key_exists($keys[16], $arr)) {
         $this->setDefaultStatuswrlLayout($arr[$keys[16]]);
     }
     if (array_key_exists($keys[17], $arr)) {
         $this->setRefreshRate($arr[$keys[17]]);
     }
     if (array_key_exists($keys[18], $arr)) {
         $this->setHostUnreachableSound($arr[$keys[18]]);
     }
     if (array_key_exists($keys[19], $arr)) {
         $this->setHostDownSound($arr[$keys[19]]);
     }
     if (array_key_exists($keys[20], $arr)) {
         $this->setServiceCriticalSound($arr[$keys[20]]);
     }
     if (array_key_exists($keys[21], $arr)) {
         $this->setServiceWarningSound($arr[$keys[21]]);
     }
     if (array_key_exists($keys[22], $arr)) {
         $this->setServiceUnknownSound($arr[$keys[22]]);
     }
     if (array_key_exists($keys[23], $arr)) {
         $this->setPingSyntax($arr[$keys[23]]);
     }
     if (array_key_exists($keys[24], $arr)) {
         $this->setEscapeHtmlTags($arr[$keys[24]]);
     }
     if (array_key_exists($keys[25], $arr)) {
         $this->setNotesUrlTarget($arr[$keys[25]]);
     }
     if (array_key_exists($keys[26], $arr)) {
         $this->setActionUrlTarget($arr[$keys[26]]);
     }
     if (array_key_exists($keys[27], $arr)) {
         $this->setEnableSplunkIntegration($arr[$keys[27]]);
     }
     if (array_key_exists($keys[28], $arr)) {
         $this->setSplunkUrl($arr[$keys[28]]);
     }
 }