Пример #1
0
// otherwise render form
if (array_key_exists("HTTP_X_REQUESTED_WITH", $_SERVER) && $_SERVER["HTTP_X_REQUESTED_WITH"] == 'XMLHttpRequest') {
    header("Content-type: text/json");
    $action = 'ajax_' . $_REQUEST["action"];
    $data = $_REQUEST["data"];
    $data = str_replace("\\\"", "\"", $data);
    $func_output = call_user_func(array($panoptes, $action), json_decode($data, true));
    print json_encode($func_output);
    exit(0);
}
$dojo_url = $panoptes->config()->getConfigValue('web.dojo-url');
if (!$dojo_url) {
    echo "No dojo url defined!";
    exit(-1);
}
$user = new userEntry();
$user->db = $panoptes->getDb();
$user->getByName($panoptes_current_user);
$userPrefs = new userPrefs();
$userPrefs->db = $panoptes->getDb();
$theme = $userPrefs->getPref($user->id, 'general', 'general_prefs_theme');
if (is_null($theme)) {
    $theme = $panoptes->config()->getConfigValue('web.default_theme');
}
$theme_css = $dojo_url . '/dijit/themes/' . $theme . '/' . $theme . '.css';
$theme_grid_css = $dojo_url . '/dojox/grid/resources/' . $theme . 'Grid.css';
$theme_e_grid_css = $dojo_url . '/dojox/grid/enhanced/resources/' . $theme . 'EnhancedGrid.css';
$chart_theme = $userPrefs->getPref($user->id, 'general', 'general_prefs_chart_theme');
if (is_null($chart_theme)) {
    $chart_theme = $panoptes->config()->getConfigValue('web.default_chart_theme');
}
Пример #2
0
 /**
  * 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;
 }
Пример #3
0
 /**
  * removeNotification
  *
  * @param args json params converted into an array
  *                  device_id optional if not null, then remove notification for 
  *                            every monitor on this device
  *                  monitor_ids array of monitor ids to remove from type if device_id not given
  *                  type monitor table
  * @throws none
  * @return array containing result and possible error messages
  */
 public function ajax_removeNotification($args)
 {
     global $panoptes_current_user;
     $result = 'success';
     $error = '';
     try {
         $user = new userEntry();
         $user->db = $this->db;
         $user->getByName($panoptes_current_user);
         if (array_key_exists('device_id', $args)) {
             // port monitors
             $rst = $this->getPortMonitorData($args['device_id']);
             foreach ($rst as $a) {
                 $a->removeNotification($user->id);
             }
             //certificate monitors
             $rst = $this->getCertificateMonitorData($args['device_id']);
             foreach ($rst as $a) {
                 $a->removeNotification($user->id);
             }
             //snmp monitors
             $rst = $this->getSNMPMonitorData($args['device_id']);
             foreach ($rst as $a) {
                 $a->removeNotification($user->id);
             }
             //shell monitors
             $rst = $this->getShellMonitorData($args['device_id']);
             foreach ($rst as $a) {
                 $a->removeNotification($user->id);
             }
             //url monitors
             $rst = $this->getUrlMonitorData($args['device_id']);
             foreach ($rst as $a) {
                 $a->removeNotification($user->id);
             }
         } else {
             foreach ($args['monitor_ids'] as $v) {
                 if ($args['type'] == 'port_monitors') {
                     require_once 'portMonitorEntry.php';
                     $ent = new portMonitorEntry($this->db);
                 } else {
                     if ($args['type'] == 'certificate_monitors') {
                         require_once 'certificateMonitorEntry.php';
                         $ent = new certificateMonitorEntry($this->db);
                     } else {
                         if ($args['type'] == 'snmp_monitors') {
                             require_once 'SNMPMonitorEntry.php';
                             $ent = new SNMPMonitorEntry($this->db);
                         } else {
                             if ($args['type'] == 'shell_monitors') {
                                 require_once 'shellMonitorEntry.php';
                                 $ent = new shellMonitorEntry($this->db);
                             } else {
                                 if ($args['type'] == 'url_monitors') {
                                     require_once 'urlMonitorEntry.php';
                                     $ent = new urlMonitorEntry($this->db);
                                 }
                             }
                         }
                     }
                 }
                 $ent->id = $v;
                 $ent->removeNotification($user->id);
             }
         }
     } catch (Exception $e) {
         return array('result' => 'failure', 'error' => $e->getMessage());
     }
     return array('result' => $result, 'error' => $error, 'data' => $data);
 }
Пример #4
0
 /**
  * deleteUserWidget
  *
  * @param args json params converted into an array
  *             pos user dashbaord widget position to delete
  * @throws none
  * @return array containing result and possible error messages
  */
 public function ajax_deleteUserWidget($args)
 {
     global $panoptes_current_user;
     $result = 'success';
     $error = '';
     $data = '';
     require_once 'userEntry.php';
     $user = new userEntry();
     $user->db = $this->db;
     $user->getByName($panoptes_current_user);
     try {
         if (array_key_exists('pos', $args)) {
             $rst = $this->getUserWidgetByPosition($args['pos']);
             if ($rst) {
                 $widgets = $this->getWidget($rst->widget_id);
                 require_once 'dashboard/' . $widgets[0]->php_file;
                 $class_name = $widgets[0]->php_class;
                 $obj = new $class_name($this->db);
                 $obj->deleteWidget($rst->position, $rst->id, $user->id);
             } else {
                 $result = 'failure';
                 $error = 'invalid widget id supplied';
             }
         } else {
             $result = 'failure';
             $error = 'no widget id supplied';
         }
     } catch (Exception $e) {
         return array('result' => 'failure', 'error' => $e->getMessage());
     }
     return array('result' => $result, 'error' => $error, 'data' => $data);
 }
Пример #5
0
 /**
  * renderUserWidget
  *
  * @param entry dashboardUserWidget object
  * @throws PDOException
  * @return none
  */
 public function renderUserWidget(dashboardUserWidget $entry)
 {
     global $panoptes_current_user;
     try {
         $rtn = array();
         $rtn['type'] = 'js';
         // make sure rrd extension is loaded
         if (!extension_loaded('RRDTool') && function_exists('rrd_fetch')) {
             // throw error for now
             // could just run cli though
             $rtn['error'] = 'php rrd extension missing';
             return $rtn;
         }
         require_once dirname(realpath(__FILE__)) . '/../panoptes.php';
         require_once dirname(realpath(__FILE__)) . '/../userEntry.php';
         require_once dirname(realpath(__FILE__)) . '/../userPrefs.php';
         $pan = new panoptes();
         // 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)) {
             $theme = $pan->config()->getConfigValue('web.default_chart_theme');
         }
         // draw rrd graph from params field of widget render last 30 minutes
         $start = sprintf("--start=%d", time() - 1800);
         $prms = $entry->params;
         $data = array();
         $rrd_params = array();
         $devices = array();
         $count = 0;
         $max_y = 0;
         foreach ($prms as $a) {
             preg_match('/^(\\d+):(.*)/', $a, $matches);
             $dev = $pan->getDevice($matches[1]);
             $short_name = preg_replace('/([^\\.]+)\\..*/', '\\1', $dev->name);
             array_push($devices, $short_name);
             $rrd_info = $pan->getRRDInfo($matches[1], $matches[2], false, $count);
             $ret = rrd_fetch($rrd_info['rrd_file'], array("AVERAGE", $start), 2);
             if (!is_array($ret)) {
                 $rtn['error'] = rrd_error();
                 return $rtn;
             } else {
                 // parse response and load data for this device into array
                 $data['_']['step'] = $ret['step'];
                 $data['_']['start'] = $ret['start'];
                 $data['_']['end'] = $ret['end'];
                 $data[$short_name] = array();
                 foreach ($ret['data'] as $k => $v) {
                     if ($v == 'NAN') {
                         $v = 0;
                     }
                     $v = round($v, 5);
                     // keep track of max value for y-axis
                     if ($v > $max_y) {
                         $max_y = $v;
                     }
                     $data[$short_name][] = array('x' => $data['_']['start'] + $k * $data['_']['step'], 'y' => $v, 'tooltip' => $v);
                 }
                 $data['_'][$short_name]['info'] = $rrd_info['datas'];
             }
             $count++;
         }
         // make title out of device names
         $devices = array_unique($devices);
         if (count($devices) > 1) {
             $last = array_pop($devices);
             $first = implode(',', $devices);
             $title = $first . ' & ' . $last;
         } else {
             $title = $devices[0];
         }
         // select a font size that will fit number of characters within 200px
         // div on most user screens
         // assume avg is 90 px/inch
         // 200px = 2.22 in
         // 72 pts/in
         // pts avail = 72 / 2.22 = 32
         $font_width = round(32 / strlen($title));
         // send back code to draw chart
         $ret = "var dv = document.createElement('div'); dv.id = '" . $entry->id . "' + '_perf_div'; dv.style.height = '175px'; dv.style.width = '200px'; node.appendChild(dv); var chrt = new dojox.charting.Chart2D('" . $entry->id . "_perf_div', { title: '" . $title . "', titleGap: 5, titleFont: 'normal normal bold " . $font_width . "pt Helvetica' }); chrt.setTheme(dojox.charting.themes." . $theme . "); chrt.addPlot('default', { type: 'Lines', markers: true }); f = new dojox.charting.action2d.Tooltip(chrt, 'default'); chrt.addAxis('x', { natural: true, htmlLabels: true, labelFunc: function(value) { var v = value; var dt = new Date(); dt.setTime(v.replace(/\\,/g,'') * 1000); var h = dt.getHours(); h = (h < 10 ? '0' + h : h); var m = dt.getMinutes(); m = (m < 10 ? '0' + m : m); return(h + ':' + m); }, microTicks: false, min: " . $data['_']['start'] . ", max: " . $data['_']['end'] . ", minorTickSpan: " . $data['_']['step'] . " }); chrt.addAxis('y', { vertical: true, min: 0, max: " . $max_y . ", includeZero: true, title: '" . $rrd_info['datas'][0]['vlabel'] . "', font: 'normal normal bold 8pt Helvetica', titleGap: 5 });";
         // go through each requested rrd and add series to chart
         foreach ($data as $k => $v) {
             if ($k != '_') {
                 $ret .= " var foo = " . json_encode($v) . "; chrt.addSeries('" . $data['_'][$k]['info'][0]['label'] . "', foo);";
             }
         }
         $ret .= " f = new dojox.charting.action2d.Tooltip(chrt, 'default'); chrt.render(); var w_lg_dv = document.createElement('div'); w_lg_dv.id = '" . $entry->id . "_legend_div'; w_lg_dv.style.height = '25px'; w_lg_dv.style.width = '200px'; node.appendChild(w_lg_dv); f = new dojox.charting.widget.Legend({ chart: chrt }, '" . $entry->id . "_legend_div');";
         $rtn['value'] = $ret;
     } catch (PDOException $e) {
         throw $e;
     }
     return $rtn;
 }