Răsfoiți Sursa

bugfix: add analyze ifindex map only for mikrotik
optimize: optimize index for some tables

root 3 ani în urmă
părinte
comite
f437c099fc

+ 3 - 3
html/admin/logs/authlog.php

@@ -35,9 +35,9 @@ if ($log_level == $L_ERROR) { $log_filter = " and (`level`=$L_INFO or `level`=$L
 if ($log_level == $L_VERBOSE) { $log_filter = " and (`level`=$L_INFO or `level`=$L_ERROR or `level`=$L_VERBOSE) "; }
 if ($log_level == $L_DEBUG) { $log_filter = ""; }
 
-if (isset($log_filter)) { $log_filter = $log_filter." and auth_id=".$auth_id; } else { $log_filter = "auth_id=".$auth_id; }
-if (isset($fcustomer)) { $log_filter = $log_filter." and customer LIKE '%".$fcustomer."%'"; }
-if (isset($fmessage)) { $log_filter = $log_filter." and message LIKE '%".$fmessage."%'"; }
+if (!empty($log_filter)) { $log_filter = $log_filter." and auth_id=".$auth_id; } else { $log_filter = "auth_id=".$auth_id; }
+if (!empty($fcustomer)) { $log_filter = $log_filter." and customer LIKE '%".$fcustomer."%'"; }
+if (!empty($fmessage)) { $log_filter = $log_filter." and message LIKE '%".$fmessage."%'"; }
 
 $countSQL="SELECT Count(*) FROM syslog WHERE `timestamp`>='$date1' AND `timestamp`<'$date2' $log_filter";
 $res = mysqli_query($db_link, $countSQL);

+ 12 - 9
html/admin/logs/index.php

@@ -35,8 +35,8 @@ if ($log_level === $L_INFO) { $log_filter = " and `level`<=$L_INFO "; }
 if ($log_level === $L_VERBOSE) { $log_filter = " and `level`<=$L_VERBOSE "; }
 if ($log_level === $L_DEBUG) { $log_filter = ""; }
 
-if (isset($fcustomer)) { $log_filter = $log_filter." and customer LIKE '%".$fcustomer."%'"; }
-if (isset($fmessage)) { $log_filter = $log_filter." and message LIKE '%".$fmessage."%'"; }
+if (!empty($fcustomer)) { $log_filter = $log_filter." and customer LIKE '%".$fcustomer."%'"; }
+if (!empty($fmessage)) { $log_filter = $log_filter." and message LIKE '%".$fmessage."%'"; }
 
 $countSQL="SELECT Count(*) FROM syslog WHERE `timestamp`>='$date1' AND `timestamp`<'$date2' $log_filter";
 $res = mysqli_query($db_link, $countSQL);
@@ -49,16 +49,19 @@ $start = ($page * $displayed) - $displayed;
 print_navigation($page_url,$page,$displayed,$count_records[0],$total);
 ?>
 <br>
-<table class="data" width="90%">
-			<tr align="center">
-				<td class="data" width=150><b>Время</b></td>
-				<td class="data"><b>Менеджер</b></td>
-				<td class="data"><b>Level</b></td>
-				<td class="data"><b>Лог</b></td>
-			</tr>
+
+<table class="data">
+<tr align="center">
+	<td class="data" width=150><b>Время</b></td>
+	<td class="data"><b>Менеджер/Источник</b></td>
+	<td class="data"><b>Level</b></td>
+	<td class="data"><b>Лог</b></td>
+</tr>
+
 <?php
 #speedup paging
 $sSQL = "SELECT `timestamp`,customer,message,level FROM syslog as S JOIN (SELECT id FROM syslog WHERE `timestamp`>='$date1' AND `timestamp`<'$date2' $log_filter ORDER BY id DESC LIMIT $start,$displayed) AS I ON S.id = I.id";
+
 $userlog = get_records_sql($db_link, $sSQL);
 foreach ($userlog as $row) {
     print "<tr align=center align=center class=\"tr1\" onmouseover=\"className='tr2'\" onmouseout=\"className='tr1'\">\n";

+ 8 - 7
html/admin/logs/mac.php

@@ -13,7 +13,7 @@ if (!isset($f_mac)) { $f_mac=''; }
 $_SESSION[$page_url]['mac']=$f_mac;
 
 $mac_where = '';
-if (isset($f_mac) and $f_mac != '') { $mac_where = " and mac='$f_mac' "; } 
+if (!empty($f_mac)) { $mac_where = " and mac='$f_mac' "; }
 
 print_log_submenu($page_url);
 ?>
@@ -40,12 +40,13 @@ print_navigation($page_url,$page,$displayed,$count_records[0],$total);
 ?>
 <br>
 <table class="data" width="850">
-	<tr align="center">
-			<td class="data" width=150><b>Время</b></td>
-			<td class="data"><b>Mac</b></td>
-			<td class="data"><b>Switch</b></td>
-			<td class="data"><b>IP</b></td>
-	</tr>
+<tr align="center">
+	<td class="data" width=150><b>Время</b></td>
+	<td class="data"><b>Mac</b></td>
+	<td class="data"><b>Switch</b></td>
+	<td class="data"><b>IP</b></td>
+</tr>
+
 <?php
 
 $sSQL = "SELECT * FROM mac_history WHERE `timestamp`>='$date1' AND `timestamp`<'$date2' $mac_where ORDER BY `timestamp` DESC LIMIT $start,$displayed";

+ 2 - 2
html/admin/logs/syslog.php

@@ -42,8 +42,8 @@ if ($f_id>0) {
 
 <?php
 
-if (isset($fmessage)) {
-    if (isset($log_filter)) { $log_filter = $log_filter." and message LIKE '%".$fmessage."%'"; } else { $log_filter = " message LIKE '%".$fmessage."%'"; }
+if (!empty($fmessage)) {
+    if (!empty($log_filter)) { $log_filter = $log_filter." and message LIKE '%".$fmessage."%'"; } else { $log_filter = " message LIKE '%".$fmessage."%'"; }
     }
 
 $countSQL="SELECT Count(*) FROM `remote_syslog` WHERE `date`>='$date1' AND `date`<'$date2' $log_filter";

+ 2 - 1
html/inc/common.php

@@ -1802,7 +1802,8 @@ global $ifmib_ifindex_map;
 global $ifmib_ifindex;
 $ifmib_map = NULL;
 $index_table =  walk_snmp($ip, $community, $version, $ifmib_ifindex_map);
-if (isset($index_table) and count($index_table) > 0) {
+$is_mikrotik = walk_snmp($ip, $community, '.1.3.6.1.2.1.9999.1.1.1.1.0', $version);
+if (isset($index_table) and count($index_table) > 0 and isset($is_mikrotik)) {
         foreach ($index_table as $key => $value) {
             $key = trim($key);
             $value = intval(trim(str_replace('INTEGER:', '', $value)));

+ 12 - 9
scripts/Rstat/snmp.pm

@@ -203,15 +203,18 @@ my $version = shift;
 my $ifmib_map;
 my $index_table =  snmp_get_oid($ip, $community, $ifIndex_map, $version);
 if (!%$index_table) { $index_table =  snmp_walk_oid($ip, $community, $ifIndex_map, $version); }
-if (%$index_table) {
-        foreach my $row (keys(%$index_table)) {
-            my $port_index = $index_table->{$row};
-            next if (!$port_index);
-            my $value;
-            if ($row=~/\.([0-9]{1,10})$/) { $value = $1; }
-            next if (!$value);
-            $ifmib_map->{$value}=$port_index;
-            };
+my $is_mikrotik = snmp_get_oid($ip, $community, '.1.3.6.1.2.1.9999.1.1.1.1.0', $version);
+if (%$index_table and $is_mikrotik) {
+	if ($is_mikrotik) {
+            foreach my $row (keys(%$index_table)) {
+	        my $port_index = $index_table->{$row};
+	        next if (!$port_index);
+        	my $value;
+                if ($row=~/\.([0-9]{1,10})$/) { $value = $1; }
+	        next if (!$value);
+    	        $ifmib_map->{$value}=$port_index;
+        	}
+	    }
         } else {
         $index_table =  snmp_get_oid($ip, $community, $ifIndex, $version);
         if (!%$index_table) { $index_table =  snmp_walk_oid($ip, $community, $ifIndex, $version); }

+ 9 - 0
updates/20220919/mysql-optimize-index.sql

@@ -0,0 +1,9 @@
+ALTER TABLE `syslog` DROP INDEX `timestamp`, ADD INDEX `timestamp` (`timestamp`) USING BTREE;
+ALTER TABLE `syslog` ADD INDEX(`level`);
+ALTER TABLE `syslog` ADD FULLTEXT(`customer`);
+ALTER TABLE `syslog` ADD INDEX(`auth_id`);
+
+ALTER TABLE `mac_history` DROP INDEX `timestamp`, ADD INDEX `timestamp` (`timestamp`) USING BTREE;
+ALTER TABLE `mac_history` DROP INDEX `timestamp_2`;
+ALTER TABLE `mac_history` ADD INDEX(`mac`);
+ALTER TABLE `mac_history` ADD INDEX(`ip`);