Esempio n. 1
0
 /**
  * Commit entry into database
  *
  * @param vals array of field names/values
  * @throws PDOException, Exception
  * @return none
  */
 public function _commit($vals)
 {
     try {
         // insert into device table if not there already
         if (is_null($this->device_id)) {
             // add deviceEntry
             require_once 'deviceEntry.php';
             $dev = new deviceEntry($this->db());
             $dev->srcaddr = $this->srcaddr;
             $dev->commit();
             $this->device_id = $dev->id;
         }
         $cols_string = '(';
         $vals_string = '(';
         foreach ($vals as $k => $v) {
             $cols_string .= $k . ",";
             $vals_string .= "'" . $v . "',";
         }
         // remove trailing ,
         $cols_string = trim($cols_string, ",");
         $vals_string = trim($vals_string, ",");
         $cols_string .= ')';
         $vals_string .= ')';
         $qry = "INSERT INTO " . $this->monitorTable() . " " . $cols_string . " VALUES " . $vals_string;
         $this->db->exec($qry);
         $this->id = $this->db->lastInsertId();
     } catch (PDOException $e) {
         throw $e;
     } catch (Exception $e) {
         throw $e;
     }
 }
Esempio n. 2
0
 /**
  * add new pingable device
  *
  * adds new pingable device and returns information needed to
  * add it to the deviceTree
  *
  * @param args json params converted into an array
  *             id device id to get data for
  * @throws none
  * @return array containing result and possible error messages
  */
 public function ajax_addPingMonitor($args)
 {
     $data = array();
     try {
         $dev = new deviceEntry();
         $dev->db($this->db);
         $dev->srcaddr = $args['address'];
         $dev->os_genre = 'unknown';
         $dev->os_detail = 'unknown';
         $dev->commit();
         $data['id'] = 'd_' . $dev->id;
         $data['type'] = 'device';
         $data['name'] = $dev->name;
         // add ping monitor
         require_once 'pingEntry.php';
         $pm = new pingEntry();
         $pm->db($this->db);
         $pm->device = $dev;
         $pm->commit();
     } catch (Exception $e) {
         return array('result' => 'failure', 'error' => $e->getMessage());
     }
     return array('result' => 'success', 'data' => $data);
 }