/**
  * renderUserWidget
  *
  * @param entry dashboardUserWidget object
  * @throws PDOException
  * @return none
  */
 public function renderUserWidget(dashboardUserWidget $entry)
 {
     global $panoptes_current_user;
     try {
         $rtn = array();
         $rtn['type'] = 'js';
         $rtn['value'] = '';
         require_once dirname(realpath(__FILE__)) . '/../deviceGroup.php';
         require_once dirname(realpath(__FILE__)) . '/../deviceEntry.php';
         require_once dirname(realpath(__FILE__)) . '/../userEntry.php';
         require_once dirname(realpath(__FILE__)) . '/../userPrefs.php';
         // get group name from id
         $prms = $entry->params;
         $grp = new deviceGroup($this->db);
         $grp->getById($prms['group_id']);
         if ($grp) {
             $counts = array();
             $counts['ok'] = 0;
             $counts['warn'] = 0;
             $counts['critical'] = 0;
             // get status for children
             foreach ($grp->children() as $c) {
                 $dev = new deviceEntry($this->db);
                 $dev->getById($c);
                 if ($dev->id) {
                     $status = $dev->maxStatus();
                     if (array_key_exists($status, $counts)) {
                         $counts[$status]++;
                     } else {
                         $counts[$status] = 1;
                     }
                 }
             }
         }
         $str = 'var groupStatusPieData = [';
         $i = 1;
         foreach ($counts as $k => $v) {
             $str .= '{ "x": "' . $i . '", "y": "' . $v . '", "text": "' . $k . '"},';
             $i++;
         }
         $str .= ']; ';
         // load user prefs for chart theme
         $user = new userEntry();
         $user->db = $this->db;
         $user->getByName($panoptes_current_user);
         $userPrefs = new userPrefs($this->db);
         $userPrefs->db = $this->db;
         $theme = $userPrefs->getPref($user->id, 'general', 'general_prefs_chart_theme');
         if (is_null($theme)) {
             require_once dirname(realpath(__FILE__)) . '/../panoptes.php';
             $panoptes = new panoptes();
             $theme = $panoptes->config()->getConfigValue('web.default_chart_theme');
         }
         $rtn['value'] .= $str;
         $rtn['value'] .= "var dv = document.createElement('div'); dv.id = '" . $prms['group_id'] . "' + '_gs_div'; dv.style.height = '200px'; dv.style.width = '200px'; node.appendChild(dv); var GS_pieChart = new dojox.charting.Chart2D('" . $prms['group_id'] . "' + '_gs_div', { title: '" . $grp->name . " summary', titleFont: 'normal normal bold 12pt Helvetica', titleGap: 5 }); GS_pieChart.setTheme(dojox.charting.themes." . $theme . "); GS_pieChart.addPlot('default', { type: 'Pie', labels: true, labelOffset: -30, radius: 50, fontColor: 'black'}); GS_pieChart.addSeries('" . $grp->name . "' + ' Summary', groupStatusPieData); new dojox.charting.action2d.MoveSlice(GS_pieChart, 'default'); GS_pieChart.render()";
     } catch (PDOException $e) {
         throw $e;
     }
     return $rtn;
 }
Example #2
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;
     }
 }
Example #3
0
 /**
  * renderUserWidget
  *
  * @param entry dashboardUserWidget object
  * @throws PDOException
  * @return none
  */
 public function renderUserWidget(dashboardUserWidget $entry)
 {
     try {
         $rtn = array();
         $rtn['type'] = 'html';
         require_once dirname(realpath(__FILE__)) . '/../deviceGroup.php';
         require_once dirname(realpath(__FILE__)) . '/../deviceEntry.php';
         // get group name from id
         $prms = $entry->params;
         $grp = new deviceGroup($this->db);
         $grp->getById($prms['group_id']);
         if ($grp) {
             $counts = array();
             $counts['ok'] = 0;
             $counts['warn'] = 0;
             $counts['critical'] = 0;
             $rtn['value'] = '<div style="font-weight: bold; font-size: larger; text-align: center;">' . $grp->name . ' summary</div/>';
             // get status for children
             foreach ($grp->children() as $c) {
                 $dev = new deviceEntry($this->db);
                 $dev->getById($c);
                 if ($dev->id) {
                     $status = $dev->maxStatus();
                     if (array_key_exists($status, $counts)) {
                         $counts[$status]++;
                     } else {
                         $counts[$status] = 1;
                     }
                 }
             }
             // add to output
             $rtn['value'] .= '<span style="font-align: left; font-weight: bold;">ok</span><span style="float: right;">' . $counts['ok'] . '</span><br/>' . "\n";
             $rtn['value'] .= '<span style="font-align: left; font-weight: bold; color: #b3511d;">warn</span><span style="float: right; color: #b3511d;">' . $counts['warn'] . '</span><br/>' . "\n";
             $rtn['value'] .= '<span style="font-align: left; font-weight: bold; color: #a62434;">critical</span><span style="float: right; color: #a62434;">' . $counts['critical'] . '</span><br/>' . "\n";
         } else {
             $rtn['value'] = '<center>unknown group id</center>';
         }
     } catch (PDOException $e) {
         throw $e;
     }
     return $rtn;
 }
Example #4
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);
 }