Example #1
0
 public function export()
 {
     // Grab our export job
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("NagiosResourceExporter attempting to export resource configuration.");
     // Grab our cgi config
     $resources = NagiosResourcePeer::doSelectOne(new Criteria());
     if (!$resources) {
         $job->addError("Unable to get Nagios Resources.  Your Lilac database is corrupt.");
         return false;
     }
     $finalArray = array();
     $values = $resources->toArray(BasePeer::TYPE_FIELDNAME);
     foreach ($values as $key => $value) {
         if ($key == 'id') {
             continue;
         }
         if (empty($value)) {
             continue;
         }
         $finalArray[$key] = $value;
     }
     $fp = $this->getOutputFile();
     fputs($fp, "# Written by NagiosResourceExporter from " . LILAC_NAME . " " . LILAC_VERSION . " on " . date("F j, Y, g:i a") . "\n\n");
     foreach ($finalArray as $key => $val) {
         fputs($fp, "\$" . strtoupper($key) . "\$" . "=" . $val . "\n");
     }
     $job->addNotice("NagiosResourceExporter complete.");
     return true;
 }
Example #2
0
 public function import()
 {
     $job = $this->getEngine()->getJob();
     $config = $this->getEngine()->getConfig();
     $resourcesCfg = new NagiosResource();
     $segment = $this->getSegment();
     $values = $segment->getValues();
     $fileName = $segment->getFilename();
     foreach ($values as $key => $entries) {
         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($resourcesCfg, $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], $resourcesCfg, $value);
                 }
             }
         }
     }
     // If we got here, it's safe to delete the existing main config and save the new one
     $oldConfig = NagiosResourcePeer::doSelectOne(new Criteria());
     if ($oldConfig) {
         $oldConfig->delete();
     }
     $resourcesCfg->save();
     $job->addNotice("NagiosResourceImporter finished importing resources configuration.");
     return true;
 }
Example #3
0
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityResourceImporter beginning to import Resources.");
     // Resources
     $res = $this->dbConn->query("SELECT * FROM nagios_resources");
     // Fruity has just one record in the resources, if we get it, import
     // it.
     $row = $res->fetch(PDO::FETCH_ASSOC);
     // Get our resources obj.
     $resourceCfg = NagiosResourcePeer::doSelectOne(new Criteria());
     if (!$resourceCfg) {
         $resourceCfg = new NagiosResource();
         $resourceCfg->save();
     }
     foreach ($row as $key => $val) {
         unset($name);
         if ($key == "id") {
             continue;
         }
         // Iterate through and, if we have a valid key, we set it to
         // the NagiosResource obj.
         try {
             $name = NagiosResourcePeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
         } catch (Exception $e) {
             $job->addNotice("Fruity Resource Importer: Was unable to store unsupported value: " . $key);
         }
         if (!empty($name)) {
             $method = "set" . $name;
             $resourceCfg->{$method}($val);
         }
     }
     $resourceCfg->save();
     // Save resources configuration
     $job->addNotice("FruityResourceImporter finished importing Resources.");
 }
Example #4
0
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 Resource
*/
include_once 'includes/config.inc';
require_once 'NagiosResource.php';
$resourceCfg = NagiosResourcePeer::doSelectOne(new Criteria());
if (!$resourceCfg) {
    $resourceCfg = new NagiosResource();
    $resourceCfg->save();
}
if (isset($_POST['request'])) {
    if ($_POST['request'] == 'update') {
        $resourceCfg->setUser1($_POST['resource_config']['user1']);
        $resourceCfg->setUser2($_POST['resource_config']['user2']);
        $resourceCfg->setUser3($_POST['resource_config']['user3']);
        $resourceCfg->setUser4($_POST['resource_config']['user4']);
        $resourceCfg->setUser5($_POST['resource_config']['user5']);
        $resourceCfg->setUser6($_POST['resource_config']['user6']);
        $resourceCfg->setUser7($_POST['resource_config']['user7']);
        $resourceCfg->setUser8($_POST['resource_config']['user8']);
        $resourceCfg->setUser9($_POST['resource_config']['user9']);
Example #5
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 = NagiosResourcePeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setUser1($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setUser2($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setUser3($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setUser4($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setUser5($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setUser6($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setUser7($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setUser8($arr[$keys[8]]);
     }
     if (array_key_exists($keys[9], $arr)) {
         $this->setUser9($arr[$keys[9]]);
     }
     if (array_key_exists($keys[10], $arr)) {
         $this->setUser10($arr[$keys[10]]);
     }
     if (array_key_exists($keys[11], $arr)) {
         $this->setUser11($arr[$keys[11]]);
     }
     if (array_key_exists($keys[12], $arr)) {
         $this->setUser12($arr[$keys[12]]);
     }
     if (array_key_exists($keys[13], $arr)) {
         $this->setUser13($arr[$keys[13]]);
     }
     if (array_key_exists($keys[14], $arr)) {
         $this->setUser14($arr[$keys[14]]);
     }
     if (array_key_exists($keys[15], $arr)) {
         $this->setUser15($arr[$keys[15]]);
     }
     if (array_key_exists($keys[16], $arr)) {
         $this->setUser16($arr[$keys[16]]);
     }
     if (array_key_exists($keys[17], $arr)) {
         $this->setUser17($arr[$keys[17]]);
     }
     if (array_key_exists($keys[18], $arr)) {
         $this->setUser18($arr[$keys[18]]);
     }
     if (array_key_exists($keys[19], $arr)) {
         $this->setUser19($arr[$keys[19]]);
     }
     if (array_key_exists($keys[20], $arr)) {
         $this->setUser20($arr[$keys[20]]);
     }
     if (array_key_exists($keys[21], $arr)) {
         $this->setUser21($arr[$keys[21]]);
     }
     if (array_key_exists($keys[22], $arr)) {
         $this->setUser22($arr[$keys[22]]);
     }
     if (array_key_exists($keys[23], $arr)) {
         $this->setUser23($arr[$keys[23]]);
     }
     if (array_key_exists($keys[24], $arr)) {
         $this->setUser24($arr[$keys[24]]);
     }
     if (array_key_exists($keys[25], $arr)) {
         $this->setUser25($arr[$keys[25]]);
     }
     if (array_key_exists($keys[26], $arr)) {
         $this->setUser26($arr[$keys[26]]);
     }
     if (array_key_exists($keys[27], $arr)) {
         $this->setUser27($arr[$keys[27]]);
     }
     if (array_key_exists($keys[28], $arr)) {
         $this->setUser28($arr[$keys[28]]);
     }
     if (array_key_exists($keys[29], $arr)) {
         $this->setUser29($arr[$keys[29]]);
     }
     if (array_key_exists($keys[30], $arr)) {
         $this->setUser30($arr[$keys[30]]);
     }
     if (array_key_exists($keys[31], $arr)) {
         $this->setUser31($arr[$keys[31]]);
     }
     if (array_key_exists($keys[32], $arr)) {
         $this->setUser32($arr[$keys[32]]);
     }
 }
Example #6
0
 /**
  * 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(NagiosResourcePeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(NagiosResourcePeer::DATABASE_NAME);
         $criteria->add(NagiosResourcePeer::ID, $pks, Criteria::IN);
         $objs = NagiosResourcePeer::doSelect($criteria, $con);
     }
     return $objs;
 }