public function _getContent($refresh = false) { $table = new CTableInfo(_('No web scenarios found.')); $table->setHeader(array(_('Website'), _('Links'), _('Broken Links'))); $data = array(); // fetch links between HTTP tests and host groups $result = DbFetchArray(DBselect('SELECT website.*, sum(status LIKE "2%") as links_ok, sum(status != "" AND NOT status LIKE "2%") as links_404, sum(status = "" OR status is null) as links_unchecked FROM zabbix_spider.website LEFT JOIN zabbix_spider.page ON page.website = Website.aid group by page.website;')); foreach ($result as $row) { $deadlinks = DbFetchArray(DBselect('SELECT * FROM zabbix_spider.page WHERE NOT status IS NULL AND status != "200" AND status != "" and website = ' . $row['aid'])); $deadlink_output = array(); $link_options = array("target" => "_blank"); foreach ($deadlinks as $deadlink) { $link_link = new CLink($deadlink['url'] == "" ? "root" : substr($deadlink['url'], 0, 50), ($deadlink['url'] == "" || $deadlink['url'][0] == "/" ? $row['url'] : "") . $deadlink['url']); $link_link->setTarget("_blank"); $map_link = new CLink("map", $this->reportUrl . "?pid={$deadlink['aid']}"); $map_link->setTarget("_blank"); $info_link = new CLink($deadlink["status"], "http://www.checkupdown.com/status/E{$deadlink['status']}.html"); $info_link->setTarget("_blank"); $deadlink_output[] = new CDiv(array($link_link, " [ ", $map_link, " | ", $info_link, " ]")); } $link_link = new CLink($row['name'], $row['url']); $link_link->setTarget("_blank"); $map_link = new CLink("map", $this->reportUrl . "?wid={$row['aid']}"); $map_link->setTarget("_blank"); $table->addRow(array(new CDiv(array($link_link, " [ ", $map_link, " ]")), new CDiv(array(new CSpan($row['links_ok'], 'green'), " / ", new CSpan($row['links_404'], 'red'), " / ", new CSpan($row['links_unchecked'], 'gray'))), new CDiv($deadlink_output))); } return $table; }
public function _getContent($refresh = false) { global $DB; $table = new CTableInfo(_('No email log data found')); $table->setHeader(array(_('System'), _('Interval'), _('Next Expected'), _('Last Seen'), _('Total Emails'), _('Actions'))); $data = array(); $db = mysql_connect("192.168.211.7", "zabbix", "asmd213)A)SDM@**@@"); $result = DbFetchArray(DBselect(' SELECT email_schedule.*,COUNT(email_match.schedule) as `email_count` FROM email_tracker.email_schedule LEFT JOIN email_tracker.email_match ON email_match.schedule = email_schedule.id GROUP BY email_schedule.id ORDER BY exec_order ')); foreach ($result as $row) { // $link_link = new CLink($row['name'],$row['url']); // $link_link->setTarget("_blank"); // $map_link = new CLink("map","/spider_report.php?wid=$row[aid]"); // $map_link->setTarget("_blank"); $color = $row['missed'] == 0 ? 'green' : 'red'; $last_seen = empty($row['last_seen']) || $row['last_seen'] == '0000-00-00 00:00:00' ? 'Never' : $row['last_seen']; $table->addRow(array(new CDiv($row['name']), new CDiv($row['expected_interval']), new CDiv($row['next_expected']), new CDiv(new CSpan($last_seen, $color)), new CDiv($row['email_count']), new CLink('Ack', '/zabbix/email.php?action=ack&id=' . $row['id']))); // if (!isset($httpTestData[$row['httptestid']])) { // $data[$row['groupid']]['unknown'] = empty($data[$row['groupid']]['unknown']) ? 1 : ++$data[$row['groupid']]['unknown']; // } // elseif ($httpTestData[$row['httptestid']]['lastfailedstep'] != 0) { // $data[$row['groupid']]['failed'] = empty($data[$row['groupid']]['failed']) ? 1 : ++$data[$row['groupid']]['failed']; // } // else { // $data[$row['groupid']]['ok'] = empty($data[$row['groupid']]['ok']) ? 1 : ++$data[$row['groupid']]['ok']; // } } return $table; }
public function _getContent($refresh = false) { if (!isset($this->config['sql'])) { return "SQL not set"; } $table = new CTableInfo($this->emptyText); $resultSet = DBselect($this->config['sql']); $result = DbFetchArray($resultSet); if (!empty($this->columns)) { $headers = array(); foreach ($this->columns as $column) { $headers[] = !empty($column['name']) ? $column['name'] : $column['field']; } } else { if (isset($result[0])) { foreach ($result[0] as $key => $value) { $headers[] = $key; $column = array('eval' => false, 'evalClass' => false, 'class' => null, 'width' => null, 'name' => $key, 'value' => $key); $this->columns[] = $column; } } else { $headers[] = "Empty Table"; } } if ($this->headers) { $table->setHeader($headers); } $index = 0; foreach ($result as $row) { $row['index'] = $index++; $crow = new CRow(null, $this->getRowClass($row)); foreach ($this->columns as $column) { $cell = new CCol($this->getValue($column, $row), $this->getClass($column, $row)); $crow->addItem($cell); } $table->addRow($crow); } return $table; }
" name="con"> </th></tr> </table> </form> <p> <?php if (count($in)) { $link = DbConnect($dbhost, $dbuser, $dbpass, $dbname); $query = GenQuery('devices', 's', '*', '', '', $in, $op, $st, $co); $res = DbQuery($query, $link); if ($res) { $prevos = ""; $oserr = 0; $ndev = 0; while ($d = DbFetchArray($res)) { if ($d['login'] and $d['cliport']) { $devip[$d['device']] = long2ip($d['devip']); if ($prevos and $prevos != $d['devos']) { $oserr = 1; } $prevos = $d['devos']; $devos[$d['device']] = $d['devos']; $devcfg[$d['device']] = $d['cfgstatus']; $devpo[$d['device']] = $d['cliport']; $devlo[$d['device']] = $d['login']; $ndev++; } else { echo "<h4>No login for {$d['device']}!</h4>\n"; } }
/** * Create and return a DIV with web monitoring overview. * * @param array $filter * @param array $filter['groupids'] * @param bool $filter['maintenance'] * * @return CDiv */ function make_webmon_overview($filter) { $groups = API::HostGroup()->get(array('groupids' => $filter['groupids'], 'hostids' => isset($filter['hostids']) ? $filter['hostids'] : null, 'monitored_hosts' => true, 'with_monitored_httptests' => true, 'output' => array('groupid', 'name'), 'preservekeys' => true)); CArrayHelper::sort($groups, array(array('field' => 'name', 'order' => ZBX_SORT_UP))); $groupIds = array_keys($groups); $availableHosts = API::Host()->get(array('groupids' => $groupIds, 'hostids' => isset($filter['hostids']) ? $filter['hostids'] : null, 'monitored_hosts' => true, 'filter' => array('maintenance_status' => $filter['maintenance']), 'output' => array('hostid'), 'preservekeys' => true)); $availableHostIds = array_keys($availableHosts); $table = new CTableInfo(_('No web scenarios found.')); $table->setHeader(array(_('Host group'), _('Ok'), _('Failed'), _('Unknown'))); $data = array(); // fetch links between HTTP tests and host groups $result = DbFetchArray(DBselect('SELECT DISTINCT ht.httptestid,hg.groupid' . ' FROM httptest ht,hosts_groups hg' . ' WHERE ht.hostid=hg.hostid' . ' AND ' . dbConditionInt('hg.hostid', $availableHostIds) . ' AND ' . dbConditionInt('hg.groupid', $groupIds) . ' AND ht.status=' . HTTPTEST_STATUS_ACTIVE)); // fetch HTTP test execution data $httpTestData = Manager::HttpTest()->getLastData(zbx_objectValues($result, 'httptestid')); foreach ($result as $row) { if (isset($httpTestData[$row['httptestid']]) && $httpTestData[$row['httptestid']]['lastfailedstep'] !== null) { if ($httpTestData[$row['httptestid']]['lastfailedstep'] != 0) { $data[$row['groupid']]['failed'] = isset($data[$row['groupid']]['failed']) ? ++$data[$row['groupid']]['failed'] : 1; } else { $data[$row['groupid']]['ok'] = isset($data[$row['groupid']]['ok']) ? ++$data[$row['groupid']]['ok'] : 1; } } else { $data[$row['groupid']]['unknown'] = isset($data[$row['groupid']]['unknown']) ? ++$data[$row['groupid']]['unknown'] : 1; } } foreach ($groups as $group) { if (!empty($data[$group['groupid']])) { $table->addRow(array(new CLink($group['name'], 'httpmon.php?groupid=' . $group['groupid'] . '&hostid=0'), new CSpan(empty($data[$group['groupid']]['ok']) ? 0 : $data[$group['groupid']]['ok'], 'off'), new CSpan(empty($data[$group['groupid']]['failed']) ? 0 : $data[$group['groupid']]['failed'], empty($data[$group['groupid']]['failed']) ? 'off' : 'on'), new CSpan(empty($data[$group['groupid']]['unknown']) ? 0 : $data[$group['groupid']]['unknown'], 'unknown'))); } } $script = new CJsScript(get_js('jQuery("#' . WIDGET_WEB_OVERVIEW . '_footer").html("' . _s('Updated: %s', zbx_date2str(TIME_FORMAT_SECONDS)) . '");')); return new CDiv(array($table, $script)); }
$query = GenQuery('devdel','i','','','',array('device','user','time'),'',array($dld,$_SESSION['user'],time()) ); if( !@DbQuery($query,$link) ){echo "<h4>".DbError($link)."</h4>";}else{echo "<h5>$dellbl $dld $updlbl OK</h5>";} $query = GenQuery('events','i','','','',array('level','time','source','info','class'),'',array('100',time(),$dld,"User $_SESSION[user] deleted this device",'usrd') ); if( !@DbQuery($query,$link) ){echo "<h4>".DbError($link)."</h4>";}else{echo "<h5>$msglbl $updlbl OK</h5>";} #old: DbQuery("DELETE FROM devices WHERE device = '".$rmdev."' LIMIT 1", $link); SteffenScholz-2011-07-05 } } } $collisions = array(); $coll_serials = array(); $devices = DbQuery("SELECT device, devip, serial, firstdis, lastdis FROM devices WHERE serial NOT REGEXP '^$|^-$|noSuch|err|n/a'", $link); #old $devices = DbQuery("SELECT name, ip, serial, firstseen, lastseen FROM devices WHERE serial REGEXP BINARY '^[-() A-Z0-9]{2,}$'", $link); SteffenScholz-2011-07-05 while ($device = DbFetchArray($devices)): if (@!in_array($device['serial'], $coll_serials)): $lookup = DbQuery("SELECT device, devip, firstdis, lastdis FROM devices WHERE serial = '".$device['serial']."' AND NOT device = '".$device['device']."'", $link); while ($colldev = DbFetchArray($lookup)): # determine reason for serial number collision # use # 1 for change from dev1 to dev2 # 2 for change from dev2 to dev1 # 0 for unknown collision reason (i.e. devices appearance times overlap) if ($colldev['firstdis'] > $device['lastdis']): $reason = 1; elseif ($colldev['lastdis'] < $device['firstdis']): $reason = 2; else: $reason = 0; endif; $collisions[] = array('serial' => $device['serial'], 'dev1_name' => $device['device'], 'dev1_ip' => $device['devip'], 'dev2_name' => $colldev['device'], 'dev2_ip' => $colldev['devip'], 'reason' => $reason); $coll_serials[] = $device['serial']; endwhile;
echo "</table></page><br><br><page orientation=\"paysage\" footer=\"\" style=\"font-size: 8px\">"; } else { echo "</table><br><br>"; } //quey number of module : count modules that is not present in devices list and have a serial number and slot not a number // for exemple in devices list appear one switch for a stack with a serial number in modules appear other switches that compose the stack $query = "select count(*) as cpt \n\t\t\tfrom devices d, stock s, modules m \n\t\t\twhere\n\t\t\td.serial = s.serial\n\t\t\tand d.name = m.device\n\t\t\tand d.serial != m.serial\n\t\t\tand m.serial !='-'\n\t\t\tand m.serial !=''\n\t\t\tand s.state=100\n\t\t\tand m.slot not regexp '^[:digit:]'\n\t\t\tand m.model != '-' {$osfilter} \n\t\t\torder by d.name, m.description"; $res = @DbQuery($query, $link); $cpt = @DbFetchArray($res); //query data for modules $query = "select m.device as name, m.model as type, m.serial as serial, m.hw as hw, m.fw as fw, m.description as description\n\t\t\tfrom devices d, stock s, modules m \n\t\t\twhere\n\t\t\td.serial = s.serial\n\t\t\tand d.name = m.device\n\t\t\tand d.serial != m.serial\n\t\t\tand m.serial !='-'\n\t\t\tand m.serial !=''\n\t\t\tand s.state=100\n\t\t\tand m.slot not regexp '^[:digit:]'\n\t\t\tand m.model != '-' {$osfilter} \n\t\t\torder by d.name, m.description"; $res = @DbQuery($query, $link); if ($res) { echo "<table class=\"content\" CELLSPACING=2 COLS=4 RULES=NONE BORDER=0>"; echo "<tr><td colspan=5 align=center style='font-size: 20px; color: white'>Inventaire des Modules: {$cpt['cpt']} unitès au " . date("d-m-Y") . ".</td></tr>"; while ($dev = @DbFetchArray($res)) { echo <<<TABLE \t\t<tr> \t\t\t<th class="imga" ROWSPAN=2 VALIGN=MIDDLE width=130 nowrap> \t\t\t\t{$dev['name']} \t\t\t</th> \t\t\t<td class="imgb" width=100 nowrap> \t\t\t\t<b>Type|</b> {$dev['type']} \t\t\t</td> \t\t\t<td class="imgb" width=150 nowrap> \t\t\t\t<b>Serial|</b> {$dev['serial']} \t\t\t</td> \t\t\t<td class="imgb" width=160 nowrap> \t\t\t\t<b>Hardware Version|</b> {$dev['hw']} \t\t\t</td> \t\t\t<td class="imgb" width=300 nowrap>
/** * Get item macros. * * @param array $macros * @param array $triggers * @param array $macroValues * * @return array */ protected function getItemMacros(array $macros, array $triggers, array $macroValues) { if ($macros) { $functions = DbFetchArray(DBselect('SELECT f.triggerid,f.functionid,i.itemid,i.value_type,i.units,i.valuemapid' . ' FROM functions f' . ' JOIN items i ON f.itemid=i.itemid' . ' JOIN hosts h ON i.hostid=h.hostid' . ' WHERE ' . dbConditionInt('f.functionid', array_keys($macros)))); $history = Manager::History()->getLast($functions, 1, ZBX_HISTORY_PERIOD); // false passed to DBfetch to get data without null converted to 0, which is done by default foreach ($functions as $func) { foreach ($macros[$func['functionid']] as $macro => $fNums) { $lastValue = isset($history[$func['itemid']]) ? $history[$func['itemid']][0]['value'] : null; switch ($macro) { case 'ITEM.LASTVALUE': $replace = $this->getItemLastValueMacro($lastValue, $func); break; case 'ITEM.VALUE': $replace = $this->getItemValueMacro($lastValue, $func, $triggers[$func['triggerid']]); break; } $macroValues = $this->getFunctionMacroValues($macroValues, $fNums, $func['triggerid'], $macro, $replace); } } } return $macroValues; }
// source not discovery i.e. trigger $table->setHeader(array(new CCol(_('Recieved'), "el_time"), new CCol(_('From/To'), "el_from_to"))); $result = DbFetchArray(DBselect(' SELECT count(*) as `total` FROM email_tracker.email_match JOIN email_tracker.email ON email_match.email = email.id WHERE ' . $timeFilter . ' ' . $scheduleFilter)); $total = 0; if (isset($result[0])) { $total = $result[0]['total']; } $pager_page = 1; if (isset($_REQUEST['page'])) { $pager_page = $_REQUEST['page']; } $pager_page = max($pager_page, 1); $limit = 25; $start = $limit * ($pager_page - 1); $result = DbFetchArray(DBselect("SELECT email.* FROM email_tracker.email_match JOIN email_tracker.email ON email_match.email = email.id WHERE {$timeFilter} {$scheduleFilter} ORDER BY email.received DESC LIMIT {$start},{$limit}")); //$sql = "SELECT * FROM logs.logs WHERE $timeFilter $serverFilter $priorityFilter ORDER BY `datetime` DESC LIMIT $start,$limit"; //echo $sql; //$results = mysql_query($sql, $db); //echo mysql_error($db); foreach ($result as $row) { // $status = isset($pMerge[$row['priority']])?$pMerge[$row['priority']]:$row['priority']; // $class = isset($cMerge[$status])?$cMerge[$status]:$status; $crow = new CRow(array($row['received'], array(new CDiv($row['subject'], 'email-subject'), new CDiv($row['from'], 'email-from'), new CDiv(implode(' ', explode(',', $row['to'])), 'email-to')))); $crow->attr('data-emailid', $row['id']); $table->addRow($crow); } $paging = pager($total, $limit, $pager_page); $t2 = new CTable('', 'email-browser'); $t2->addRow(array(new CDiv('', 'email-above-list'), array(new CDiv(array(new CDiv('', 'email-header')), 'email-viewer')))); $t2->addRow(array(new CDiv(array($table, $paging), 'email-list'), new CIFrame('', null, null, 'yes', 'email-body')));
** 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. **/ $groups = API::HostGroup()->get(['output' => ['groupid', 'name'], 'groupids' => $data['filter']['groupids'], 'hostids' => isset($data['filter']['hostids']) ? $data['filter']['hostids'] : null, 'monitored_hosts' => true, 'with_monitored_httptests' => true, 'preservekeys' => true]); CArrayHelper::sort($groups, ['name']); $groupIds = array_keys($groups); $availableHosts = API::Host()->get(['output' => ['hostid'], 'groupids' => $groupIds, 'hostids' => isset($data['filter']['hostids']) ? $data['filter']['hostids'] : null, 'filter' => ['maintenance_status' => $data['filter']['maintenance']], 'monitored_hosts' => true, 'preservekeys' => true]); $availableHostIds = array_keys($availableHosts); $table_data = []; // fetch links between HTTP tests and host groups $result = DbFetchArray(DBselect('SELECT DISTINCT ht.httptestid,hg.groupid' . ' FROM httptest ht,hosts_groups hg' . ' WHERE ht.hostid=hg.hostid' . ' AND ' . dbConditionInt('hg.hostid', $availableHostIds) . ' AND ' . dbConditionInt('hg.groupid', $groupIds) . ' AND ht.status=' . HTTPTEST_STATUS_ACTIVE)); // fetch HTTP test execution data $httpTestData = Manager::HttpTest()->getLastData(zbx_objectValues($result, 'httptestid')); foreach ($result as $row) { if (!array_key_exists($row['groupid'], $table_data)) { $table_data[$row['groupid']] = ['ok' => 0, 'failed' => 0, 'unknown' => 0]; } if (isset($httpTestData[$row['httptestid']]) && $httpTestData[$row['httptestid']]['lastfailedstep'] !== null) { $table_data[$row['groupid']][$httpTestData[$row['httptestid']]['lastfailedstep'] != 0 ? 'failed' : 'ok']++; } else { $table_data[$row['groupid']]['unknown']++; } } $table = (new CTableInfo())->setHeader([_('Host group'), _('Ok'), _('Failed'), _('Unknown')]); foreach ($groups as $group) { if (array_key_exists($group['groupid'], $table_data)) {
// build the string, looks like "UserName = '******'UserName']; } } else { print @DbError($radlink); } $sta = implode('|', $guser); // do the final query $radquery = Query('userinfo', '*', "UserName", 'regexp', "^({$sta})\$", '', '', '', '', $_GET[ord], ''); } else { $radquery = Query('userinfo', '*', '', '', '', '', '', '', '', $_GET[ord], ''); } $radres = @DbQuery($radquery, $radlink); $nres = 0; if ($radres) { while ($u = @DbFetchArray($radres)) { // zuerst allet in variablen schreiebn, danach online SQL statement ausfuehren // radusr[$nres]["UserName"] = $u['UserName']; // radusr[$nres]["Name"] = $u['Name']; // radusr[$nres]["Mail"] = $u['Mail']; // radusr[$nres]["WorkPhone"] = $u['WorkPhone']; //radusr[$nres]["Online"] = $u['WorkPhone']; if ($row == "1") { $row = "0"; $bg = $bga; $bi = $bia; } else { $row = "1"; $bg = $bgb; $bi = $bib; }
function DbCsv($res, $sep, $quotes, $outfile) { // The CSV file is created and opened $csvfile = fopen($outfile, "w"); // The rows of the given result are processed one after the other while ($row = DbFetchArray($res)) { $csv = ""; //preg_match("/^(origip|ip)$/",$c) // Each element is added to the string individually foreach ($row as $id => $field) { if (preg_match("/^(origip|ip)\$/", $id)) { $field = long2ip($field); } // If quotes are wished, they are put around the element if ($quotes == "on") { $csv .= "\""; } $csv .= $field; if ($quotes == "on") { $csv .= "\""; } $csv .= $sep; } // The last separator of a line is always cut off $csv = trim($csv, $sep); // For each row a single line of the file is used $csv .= "\r\n"; // After having prepared the CSV row, it is written to the file fwrite($csvfile, $csv); } // When finished, the CSV file is closed fclose($csvfile); }
if (!DbQuery($query, $link)) { echo "<h4>" . DbError($link) . "</h4>"; } else { echo "<h5>{$dellbl} {$ina} {$opa} {$sta} OK</h5>"; } } if (count($in)) { Condition($in, $op, $st, $co); TblHead("{$modgroup[$self]}2", 1); $query = GenQuery('nodetrack', 's', 'nodetrack.device as device,nodetrack.ifname as ifname,value,source,alias,comment,name,nodes.mac as mac,oui,nodes.vlanid as vlanid,usrname,time', $ord, $lim, $in, $op, $st, $co, 'JOIN interfaces USING (device,ifname) LEFT JOIN nodes USING (device,ifname)'); $res = DbQuery($query, $link); if ($res) { $usta = urlencode($sta); $uopa = urlencode($opa); $row = 0; while ($trk = DbFetchArray($res)) { if ($row % 2) { $bg = "txta"; $bi = "imga"; } else { $bg = "txtb"; $bi = "imgb"; } $row++; $cfgst = ''; list($cc, $lc) = Agecol($trk['time'], $trk['time'], $row % 2); if ($dev and $dev == $trk['device'] and $ifn and $ifn == $trk['ifname']) { $time = time(); if ($src) { if ($src == '-') { $setd = '';
</b></center></div> <?php } if ($_POST['~']) { $result = DbQuery("SELECT device, devip FROM devices WHERE device REGEXP BINARY '" . $_POST['expression'] . "'", $link); ?> <div class="textpad devConf"> <?php if (DbNumRows($result)) { ?> <b>Hosts matching regular expression '<?php echo $_POST['expression']; ?> ':</b><br> <?php while ($row = DbFetchArray($result)) { ?> <br><?php echo $row['device']; ?> (<?php echo long2ip($row['devip']); ?> ) <?php } } else { ?> Regular expression '<?php echo $_POST['expression']; ?>
$radusr[$nres]["UserName"] = $u['UserName']; $radusr[$nres]["Name"] = $u['Name']; $radusr[$nres]["Department"] = $u['Department']; $radusr[$nres]["Mail"] = $u['Mail']; $radusr[$nres]["WorkPhone"] = $u['WorkPhone']; $nres++; } @DbFreeResult($radres); } else { print @DbError($radlink); } // get online status on these users for ($i = 0; $i < $nres; $i++) { $radquery = Query('radacct', '*', 'UserName', '=', $radusr[$i]["UserName"], 'AND', 'AcctStopTime', '=', '0', $_GET[ord], ''); $radres = @DbQuery($radquery, $radlink); if ($u = @DbFetchArray($radres)) { $radusr[$i]["Online"] = true; $radusr[$i]["NAS"] = $u['NASIPAddress']; } else { $radusr[$i]["Online"] = false; $radusr[$i]["NAS"] = ''; } @DbFreeResult($radres); } // print for ($i = 0; $i < $nres; $i++) { if ($row == "1") { $row = "0"; $bg = $bga; $bi = $bia; } else {
function DbDump($tables, $link, $outfile) { // The dump file is created and opened $sqlfile = fopen($outfile, "w"); // The comment header for the MySQL dump is created... $sql = "--\n"; $sql .= "-- NeDi MySQL Dump - " . date("d M Y H:i") . "\n"; $sql .= "-- ------------------------------------------------------\n\n"; // ...and written to the file fwrite($sqlfile, $sql); $sql = ""; // All the tables are dumped one after the other foreach ($tables as $tbl) { // Some SQL comments $sql .= "--\n"; $sql .= "-- Table structure for table `" . $tbl . "`\n"; $sql .= "--\n\n"; // This is to make sure, that there is no table with the same name $sql .= "DROP TABLE IF EXISTS `" . $tbl . "`;\n"; // This query gives us the complete SQL query to create the table structure $res = DbQuery("SHOW CREATE TABLE `{$tbl}`;", $link); $field = array(); while ($field = DbFetchArray($res)) { // Now the SQL command used to create the table structure is read from the database $sql .= $field['Create Table'] . ";\n\n"; } // Another block of SQL comments $sql .= "--\n"; $sql .= "-- Dumping data for table `" . $tbl . "`\n"; $sql .= "--\n\n"; // To make sure, that we are the only one working on the table, when importing the dump, // this SQL command is used $sql .= "LOCK TABLES `" . $tbl . "` WRITE;\n"; $chfields = array(); $field = array(); // We want to check each column of the table, if its datatype is numeric or not. // Because if it's not numeric, we want to surround the content in the INSERT command // with "". But if it is numeric we must not put "" around the content. $res = DbQuery("DESCRIBE `{$tbl}`;", $link); while ($field = DbFetchArray($res)) { // If a field is either of type "varchar()" or "text" the we add a '1' to the array... if (substr($field['Type'], 0, 8) == "varchar(" || $field['Type'] == "text") { $chfields[] = 1; } else { $chfields[] = 0; } } // The data, which we gathered since the last time we wrote something to the file // is written down to the SQL dump file. fwrite($sqlfile, $sql); $sql = ""; // Now we want to have all the data from the table $res = DbQuery(GenQuery($tbl, "s", "*"), $link); // $res = DbQuery("SELECT * FROM `".$tbl."`;", $link); $field = array(); while ($field = DbFetchRow($res)) { // For each record a new INSERT command is created $sql .= "INSERT INTO `" . $tbl . "` VALUES ("; // The fields of the record are inserted one after the other for ($i = 0; $i < count($field); $i++) { // If the current field is a "varchar()" or "text" field // then it is surrounded by "". The array $chfields[] // tells us, if the current field is numeric (0) or not (1). if ($chfields[$i] == 1 && $field[$i] != "") { $sql .= "\""; } if ($field[$i] != "") { $field[$i] = str_replace("\"", "\\\"", $field[$i]); $sql .= $field[$i]; } else { $sql .= "NULL"; } if ($chfields[$i] == 1 && $field[$i] != "") { $sql .= "\""; } if ($i < count($field) - 1) { $sql .= ", "; } } $sql .= ");\n"; // The INSERT command for the current record is written to the dump file fwrite($sqlfile, $sql); $sql = ""; } // After having inserted all the data to the database table // the table can be unlocked $sql .= "UNLOCK TABLES;\n\n"; fwrite($sqlfile, $sql); $sql = ""; } // Finally the SQL dump file is closed fclose($sqlfile); }
/** * Create and return a DIV with web monitoring overview. * * @param array $filter * @param array $filter['groupids'] * @param bool $filter['maintenance'] * * @return CDiv */ function make_webmon_overview($filter) { $groups = API::HostGroup()->get(array('groupids' => $filter['groupids'], 'hostids' => isset($filter['hostids']) ? $filter['hostids'] : null, 'monitored_hosts' => true, 'with_monitored_httptests' => true, 'output' => array('groupid', 'name'), 'preservekeys' => true)); foreach ($groups as &$group) { $group['nodename'] = get_node_name_by_elid($group['groupid']); } unset($group); CArrayHelper::sort($groups, array(array('field' => 'nodename', 'order' => ZBX_SORT_UP), array('field' => 'name', 'order' => ZBX_SORT_UP))); $groupIds = array_keys($groups); $availableHosts = API::Host()->get(array('groupids' => $groupIds, 'hostids' => isset($filter['hostids']) ? $filter['hostids'] : null, 'monitored_hosts' => true, 'filter' => array('maintenance_status' => $filter['maintenance']), 'output' => array('hostid'), 'preservekeys' => true)); $availableHostIds = array_keys($availableHosts); $table = new CTableInfo(_('No web scenarios found.')); $table->setHeader(array(is_show_all_nodes() ? _('Node') : null, _('Host group'), _('Ok'), _('Failed'), _('Unknown'))); $data = array(); // fetch links between HTTP tests and host groups $result = DbFetchArray(DBselect('SELECT DISTINCT ht.httptestid,hg.groupid' . ' FROM httptest ht,hosts_groups hg' . ' WHERE ht.hostid=hg.hostid' . ' AND ' . dbConditionInt('hg.hostid', $availableHostIds) . ' AND ' . dbConditionInt('hg.groupid', $groupIds))); // fetch HTTP test execution data $httpTestData = Manager::HttpTest()->getLastData(zbx_objectValues($result, 'httptestid')); foreach ($result as $row) { if (!isset($httpTestData[$row['httptestid']])) { $data[$row['groupid']]['unknown'] = empty($data[$row['groupid']]['unknown']) ? 1 : ++$data[$row['groupid']]['unknown']; } elseif ($httpTestData[$row['httptestid']]['lastfailedstep'] != 0) { $data[$row['groupid']]['failed'] = empty($data[$row['groupid']]['failed']) ? 1 : ++$data[$row['groupid']]['failed']; } else { $data[$row['groupid']]['ok'] = empty($data[$row['groupid']]['ok']) ? 1 : ++$data[$row['groupid']]['ok']; } } foreach ($groups as $group) { if (!empty($data[$group['groupid']])) { $table->addRow(array(is_show_all_nodes() ? $group['nodename'] : null, $group['name'], new CSpan(empty($data[$group['groupid']]['ok']) ? 0 : $data[$group['groupid']]['ok'], 'off'), new CSpan(empty($data[$group['groupid']]['failed']) ? 0 : $data[$group['groupid']]['failed'], empty($data[$group['groupid']]['failed']) ? 'off' : 'on'), new CSpan(empty($data[$group['groupid']]['unknown']) ? 0 : $data[$group['groupid']]['unknown'], 'unknown'))); } } $script = new CJSScript(get_js("jQuery('#hat_webovr_footer').html('" . _s('Updated: %s', zbx_date2str(_('H:i:s'))) . "')")); return new CDiv(array($table, $script)); }
<input type="submit" value="Configure" name="con"> </th></tr> </table> </form> <p> <? if($ina){ $link = @DbConnect($dbhost,$dbuser,$dbpass,$dbname); $query = GenQuery('devices','s','*','','',array($ina,$inb),array($opa,$opb),array($sta,$stb),array($cop) ); $res = @DbQuery($query,$link); if($res){ $prevos = ""; $oserr = 0; while( ($d = @DbFetchArray($res)) ){ if($d['login'] and $d['cliport']){ $devip[$d['name']] = long2ip($d['ip']); if ($prevos and $prevos != $d['os']){$oserr = 1;} $prevos = $d['os']; $devos[$d['name']] = $d['os']; $devsta[$d['name']] = $d[$ina]; $devstb[$d['name']] = $d[$inb]; $devpo[$d['name']] = $d['cliport']; $devlo[$d['name']] = $d['login']; }else{ echo "<h4>No login for $d[0]!</h4>\n"; } } $cf = "log/cmd_$_SESSION[user]"; if ($oserr){echo "<h4>OS $n1rmsg</h4>";die;}