@@ -96,8 +96,7 @@ discard block |
||
| 96 | 96 | } |
| 97 | 97 | $this->trapLog($message,$log_level,'syslog'); |
| 98 | 98 | return false; |
| 99 | - } |
|
| 100 | - else |
|
| 99 | + } else |
|
| 101 | 100 | { |
| 102 | 101 | $option_var=$option_array[$option_category][$option_name]; |
| 103 | 102 | return true; |
@@ -144,7 +143,9 @@ discard block |
||
| 144 | 143 | protected function getDBConfigIfSet($element,&$variable) |
| 145 | 144 | { |
| 146 | 145 | $value=$this->getDBConfig($element); |
| 147 | - if ($value != 'null') $variable=$value; |
|
| 146 | + if ($value != 'null') { |
|
| 147 | + $variable=$value; |
|
| 148 | + } |
|
| 148 | 149 | } |
| 149 | 150 | |
| 150 | 151 | /** Get data from db_config |
@@ -180,8 +181,11 @@ discard block |
||
| 180 | 181 | $message = '['. date("Y/m/d H:i:s") . '] ' . |
| 181 | 182 | '['. basename(__FILE__) . '] ['.$this->debug_text[$level].']: ' .$message . "\n"; |
| 182 | 183 | |
| 183 | - if ( $destination != '' ) $output=$destination; |
|
| 184 | - else $output=$this->alert_output; |
|
| 184 | + if ( $destination != '' ) { |
|
| 185 | + $output=$destination; |
|
| 186 | + } else { |
|
| 187 | + $output=$this->alert_output; |
|
| 188 | + } |
|
| 185 | 189 | switch ($output) |
| 186 | 190 | { |
| 187 | 191 | case 'file': |
@@ -217,7 +221,9 @@ discard block |
||
| 217 | 221 | switch ($output_type) |
| 218 | 222 | { |
| 219 | 223 | case 'file': |
| 220 | - if ($output_option == null) throw new Exception("File logging without file !"); |
|
| 224 | + if ($output_option == null) { |
|
| 225 | + throw new Exception("File logging without file !"); |
|
| 226 | + } |
|
| 221 | 227 | $this->debug_file=$output_option; |
| 222 | 228 | $this->alert_output='file'; |
| 223 | 229 | break; |
@@ -312,16 +318,14 @@ discard block |
||
| 312 | 318 | $this->trapLog("No Config/database in config file: ".$this->trap_module_config,ERROR,''); |
| 313 | 319 | } |
| 314 | 320 | $db_name=$trap_config['config']['database']; |
| 315 | - } |
|
| 316 | - else if ($database == 'ido') |
|
| 321 | + } else if ($database == 'ido') |
|
| 317 | 322 | { |
| 318 | 323 | if (!isset($trap_config['config']['IDOdatabase'])) |
| 319 | 324 | { |
| 320 | 325 | $this->trapLog("No Config/IDOdatabase in config file: ".$this->trap_module_config,ERROR,''); |
| 321 | 326 | } |
| 322 | 327 | $db_name=$trap_config['config']['IDOdatabase']; |
| 323 | - } |
|
| 324 | - else |
|
| 328 | + } else |
|
| 325 | 329 | { |
| 326 | 330 | $this->trapLog("Unknown database type : ".$database,ERROR,''); |
| 327 | 331 | return null; |
@@ -341,8 +345,12 @@ discard block |
||
| 341 | 345 | $db_sql_name=$db_config[$db_name]['dbname']; |
| 342 | 346 | $db_user=$db_config[$db_name]['username']; |
| 343 | 347 | $db_pass=$db_config[$db_name]['password']; |
| 344 | - if ($database == 'traps') $this->trapDBType = $db_type; |
|
| 345 | - if ($database == 'ido') $this->idoDBType = $db_type; |
|
| 348 | + if ($database == 'traps') { |
|
| 349 | + $this->trapDBType = $db_type; |
|
| 350 | + } |
|
| 351 | + if ($database == 'ido') { |
|
| 352 | + $this->idoDBType = $db_type; |
|
| 353 | + } |
|
| 346 | 354 | |
| 347 | 355 | $this->trapLog( "DB selected : $db_type $db_host $db_sql_name $db_user",3,''); |
| 348 | 356 | return array($db_type,$db_host,$db_sql_name,$db_user,$db_pass); |
@@ -384,8 +392,7 @@ discard block |
||
| 384 | 392 | { |
| 385 | 393 | $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)"); |
| 386 | 394 | $this->trapLog('Error parsing IP : '.$IP,ERROR,''); |
| 387 | - } |
|
| 388 | - else |
|
| 395 | + } else |
|
| 389 | 396 | { |
| 390 | 397 | $this->trap_data['source_ip']=$matches[1]; |
| 391 | 398 | $this->trap_data['destination_ip']=$matches[3]; |
@@ -400,14 +407,12 @@ discard block |
||
| 400 | 407 | if ($ret_code===0 || $ret_code===false) |
| 401 | 408 | { |
| 402 | 409 | $this->trapLog('No match on trap data : '.$vars,WARN,''); |
| 403 | - } |
|
| 404 | - else |
|
| 410 | + } else |
|
| 405 | 411 | { |
| 406 | 412 | if (($matches[1]=='.1.3.6.1.6.3.1.1.4.1.0') || ($matches[1]=='.1.3.6.1.6.3.1.1.4.1')) |
| 407 | 413 | { |
| 408 | 414 | $this->trap_data['trap_oid']=$matches[2]; |
| 409 | - } |
|
| 410 | - else |
|
| 415 | + } else |
|
| 411 | 416 | { |
| 412 | 417 | $object= new stdClass; |
| 413 | 418 | $object->oid =$matches[1]; |
@@ -576,7 +581,9 @@ discard block |
||
| 576 | 581 | } |
| 577 | 582 | |
| 578 | 583 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
| 579 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 584 | + if ($inserted_id==false) { |
|
| 585 | + throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 586 | + } |
|
| 580 | 587 | $this->trap_id=$inserted_id; |
| 581 | 588 | break; |
| 582 | 589 | default: |
@@ -592,7 +599,9 @@ discard block |
||
| 592 | 599 | { |
| 593 | 600 | |
| 594 | 601 | // If action is ignore -> don't send t DB |
| 595 | - if ($this->trap_to_db === false) return; |
|
| 602 | + if ($this->trap_to_db === false) { |
|
| 603 | + return; |
|
| 604 | + } |
|
| 596 | 605 | |
| 597 | 606 | |
| 598 | 607 | $db_conn=$this->db_connect_trap(); |
@@ -649,7 +658,9 @@ discard block |
||
| 649 | 658 | } |
| 650 | 659 | |
| 651 | 660 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
| 652 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 661 | + if ($inserted_id==false) { |
|
| 662 | + throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 663 | + } |
|
| 653 | 664 | $this->trap_id=$inserted_id; |
| 654 | 665 | break; |
| 655 | 666 | default: |
@@ -778,8 +789,7 @@ discard block |
||
| 778 | 789 | // TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default.... |
| 779 | 790 | exec('echo "'.$send.'" > ' .$this->icinga2cmd); |
| 780 | 791 | return true; |
| 781 | - } |
|
| 782 | - else |
|
| 792 | + } else |
|
| 783 | 793 | { |
| 784 | 794 | $api = $this->getAPI(); |
| 785 | 795 | $api->setCredentials($this->api_username, $this->api_password); |
@@ -788,8 +798,7 @@ discard block |
||
| 788 | 798 | { |
| 789 | 799 | $this->trapLog( "Error sending result : " .$retmessage,WARN,''); |
| 790 | 800 | return false; |
| 791 | - } |
|
| 792 | - else |
|
| 801 | + } else |
|
| 793 | 802 | { |
| 794 | 803 | $this->trapLog( "Sent result : " .$retmessage,3,''); |
| 795 | 804 | return true; |
@@ -849,7 +858,9 @@ discard block |
||
| 849 | 858 | /***************** Eval & tokenizer functions ****************/ |
| 850 | 859 | protected function eval_getElement($rule,&$item) |
| 851 | 860 | { |
| 852 | - while ($rule[$item]==' ') $item++; |
|
| 861 | + while ($rule[$item]==' ') { |
|
| 862 | + $item++; |
|
| 863 | + } |
|
| 853 | 864 | if (preg_match('/[0-9\.]/',$rule[$item])) |
| 854 | 865 | { // number |
| 855 | 866 | |
@@ -876,14 +887,15 @@ discard block |
||
| 876 | 887 | $start=$item; |
| 877 | 888 | $parenthesis_count=0; |
| 878 | 889 | while (($item < strlen($rule)) // Not end of string AND |
| 879 | - && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded () |
|
| 890 | + && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) { |
|
| 891 | + // Closing ')' or embeded () |
|
| 880 | 892 | { |
| 881 | 893 | if ($rule[$item] == '"' ) |
| 882 | 894 | { // pass through string |
| 883 | 895 | $item++; |
| 896 | + } |
|
| 884 | 897 | $item=$this->eval_getNext($rule,$item,'"'); |
| 885 | - } |
|
| 886 | - else{ |
|
| 898 | + } else{ |
|
| 887 | 899 | if ($rule[$item] == '(') |
| 888 | 900 | { |
| 889 | 901 | $parenthesis_count++; |
@@ -911,13 +923,17 @@ discard block |
||
| 911 | 923 | protected function eval_getNext($rule,$item,$tok) |
| 912 | 924 | { |
| 913 | 925 | while (($rule[$item] != $tok ) && ($item < strlen($rule))) { $item++;} |
| 914 | - if ($item==strlen($rule)) throw new Exception("closing '".$tok."' not found in ".$rule ." at " .$item); |
|
| 926 | + if ($item==strlen($rule)) { |
|
| 927 | + throw new Exception("closing '".$tok."' not found in ".$rule ." at " .$item); |
|
| 928 | + } |
|
| 915 | 929 | return $item+1; |
| 916 | 930 | } |
| 917 | 931 | |
| 918 | 932 | protected function eval_getOper($rule,&$item) |
| 919 | 933 | { |
| 920 | - while ($rule[$item]==' ') $item++; |
|
| 934 | + while ($rule[$item]==' ') { |
|
| 935 | + $item++; |
|
| 936 | + } |
|
| 921 | 937 | switch ($rule[$item]) |
| 922 | 938 | { |
| 923 | 939 | case '<': |
@@ -953,12 +969,13 @@ discard block |
||
| 953 | 969 | public function evaluation($rule,&$item) |
| 954 | 970 | { |
| 955 | 971 | //echo "Evaluation of ".substr($rule,$item)."\n"; |
| 956 | - if ( $rule[$item] == '!') // If '!' found, negate next expression. |
|
| 972 | + if ( $rule[$item] == '!') { |
|
| 973 | + // If '!' found, negate next expression. |
|
| 957 | 974 | { |
| 958 | 975 | $negate=true; |
| 959 | - $item++; |
|
| 960 | 976 | } |
| 961 | - else |
|
| 977 | + $item++; |
|
| 978 | + } else |
|
| 962 | 979 | { |
| 963 | 980 | $negate=false; |
| 964 | 981 | } |
@@ -966,10 +983,14 @@ discard block |
||
| 966 | 983 | list($type1,$val1) = $this->eval_getElement($rule,$item); |
| 967 | 984 | //echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n"; |
| 968 | 985 | |
| 969 | - if ($item==strlen($rule)) // If only element, return value, but only boolean |
|
| 986 | + if ($item==strlen($rule)) { |
|
| 987 | + // If only element, return value, but only boolean |
|
| 970 | 988 | { |
| 971 | 989 | if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule); |
| 972 | - if ($negate === true) $val1= ! $val1; |
|
| 990 | + } |
|
| 991 | + if ($negate === true) { |
|
| 992 | + $val1= ! $val1; |
|
| 993 | + } |
|
| 973 | 994 | return $val1; |
| 974 | 995 | } |
| 975 | 996 | |
@@ -978,27 +999,34 @@ discard block |
||
| 978 | 999 | //echo "Comp : ".$comp." : ".substr($rule,$item)."\n"; |
| 979 | 1000 | |
| 980 | 1001 | // Third element : number, string or () |
| 981 | - if ( $rule[$item] == '!') // starts with a ! so evaluate whats next |
|
| 1002 | + if ( $rule[$item] == '!') { |
|
| 1003 | + // starts with a ! so evaluate whats next |
|
| 982 | 1004 | { |
| 983 | 1005 | $item++; |
| 984 | - if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule); |
|
| 1006 | + } |
|
| 1007 | + if ($typec != 1) { |
|
| 1008 | + throw new Exception("Mixing boolean and comparison : ".$rule); |
|
| 1009 | + } |
|
| 985 | 1010 | $val2= ! $this->evaluation($rule,$item); |
| 986 | 1011 | $type2=2; // result is a boolean |
| 987 | - } |
|
| 988 | - else |
|
| 1012 | + } else |
|
| 989 | 1013 | { |
| 990 | 1014 | list($type2,$val2) = $this->eval_getElement($rule,$item); |
| 991 | 1015 | } |
| 992 | 1016 | //echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n"; |
| 993 | 1017 | |
| 994 | - if ($type1!=$type2) // cannot compare different types |
|
| 1018 | + if ($type1!=$type2) { |
|
| 1019 | + // cannot compare different types |
|
| 995 | 1020 | { |
| 996 | 1021 | throw new Exception("Cannot compare string & number : ".$rule); |
| 997 | 1022 | } |
| 998 | - if ($typec==1 && $type1 !=2) // cannot use & or | with string/number |
|
| 1023 | + } |
|
| 1024 | + if ($typec==1 && $type1 !=2) { |
|
| 1025 | + // cannot use & or | with string/number |
|
| 999 | 1026 | { |
| 1000 | 1027 | throw new Exception("Cannot use boolean operators with string & number : ".$rule); |
| 1001 | 1028 | } |
| 1029 | + } |
|
| 1002 | 1030 | |
| 1003 | 1031 | switch ($comp){ |
| 1004 | 1032 | case '<': $retVal= ($val1 < $val2); break; |
@@ -1012,9 +1040,15 @@ discard block |
||
| 1012 | 1040 | case '&': $retVal= ($val1 && $val2); break; |
| 1013 | 1041 | default: throw new Exception("Error in expression - unknown comp : ".$comp); |
| 1014 | 1042 | } |
| 1015 | - if ($negate === true) $retVal = ! $retVal; // Inverse result if negate before expression |
|
| 1043 | + if ($negate === true) { |
|
| 1044 | + $retVal = ! $retVal; |
|
| 1045 | + } |
|
| 1046 | + // Inverse result if negate before expression |
|
| 1016 | 1047 | |
| 1017 | - if ($item==strlen($rule)) return $retVal; // End of string : return evaluation |
|
| 1048 | + if ($item==strlen($rule)) { |
|
| 1049 | + return $retVal; |
|
| 1050 | + } |
|
| 1051 | + // End of string : return evaluation |
|
| 1018 | 1052 | // check for logical operator : |
| 1019 | 1053 | switch ($rule[$item]) |
| 1020 | 1054 | { |
@@ -1041,7 +1075,9 @@ discard block |
||
| 1041 | 1075 | $rule2.=$rule[$item]; |
| 1042 | 1076 | $item++; |
| 1043 | 1077 | } |
| 1044 | - if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
| 1078 | + if ($item == strlen ($rule)) { |
|
| 1079 | + throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
| 1080 | + } |
|
| 1045 | 1081 | $rule2.=$rule[$item]; |
| 1046 | 1082 | $item++; |
| 1047 | 1083 | continue; |
@@ -1061,10 +1097,12 @@ discard block |
||
| 1061 | 1097 | |
| 1062 | 1098 | protected function eval_rule($rule) |
| 1063 | 1099 | { |
| 1064 | - if ($rule==null || $rule == '') // Empty rule is always true |
|
| 1100 | + if ($rule==null || $rule == '') { |
|
| 1101 | + // Empty rule is always true |
|
| 1065 | 1102 | { |
| 1066 | 1103 | return true; |
| 1067 | 1104 | } |
| 1105 | + } |
|
| 1068 | 1106 | $matches=array(); |
| 1069 | 1107 | while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1) |
| 1070 | 1108 | { |
@@ -1151,20 +1189,17 @@ discard block |
||
| 1151 | 1189 | if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false) |
| 1152 | 1190 | { |
| 1153 | 1191 | $this->trap_action.='Error sending status : check cmd/API'; |
| 1154 | - } |
|
| 1155 | - else |
|
| 1192 | + } else |
|
| 1156 | 1193 | { |
| 1157 | 1194 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
| 1158 | 1195 | $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name; |
| 1159 | 1196 | } |
| 1160 | - } |
|
| 1161 | - else |
|
| 1197 | + } else |
|
| 1162 | 1198 | { |
| 1163 | 1199 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
| 1164 | 1200 | } |
| 1165 | 1201 | $this->trap_to_db=($action==-2)?false:true; |
| 1166 | - } |
|
| 1167 | - else |
|
| 1202 | + } else |
|
| 1168 | 1203 | { |
| 1169 | 1204 | //$this->trapLog('rules KOO : '.print_r($rule),3,''); |
| 1170 | 1205 | |
@@ -1175,14 +1210,12 @@ discard block |
||
| 1175 | 1210 | if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false) |
| 1176 | 1211 | { |
| 1177 | 1212 | $this->trap_action.='Error sending status : check cmd/API'; |
| 1178 | - } |
|
| 1179 | - else |
|
| 1213 | + } else |
|
| 1180 | 1214 | { |
| 1181 | 1215 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
| 1182 | 1216 | $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name; |
| 1183 | 1217 | } |
| 1184 | - } |
|
| 1185 | - else |
|
| 1218 | + } else |
|
| 1186 | 1219 | { |
| 1187 | 1220 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
| 1188 | 1221 | } |
@@ -1192,16 +1225,14 @@ discard block |
||
| 1192 | 1225 | if (!isset($this->trap_data['source_name'])) |
| 1193 | 1226 | { |
| 1194 | 1227 | $this->trap_data['source_name']=$rule['host_name']; |
| 1195 | - } |
|
| 1196 | - else |
|
| 1228 | + } else |
|
| 1197 | 1229 | { |
| 1198 | 1230 | if (!preg_match('/'.$rule['host_name'].'/',$this->trap_data['source_name'])) |
| 1199 | 1231 | { // only add if not present |
| 1200 | 1232 | $this->trap_data['source_name'].=','.$rule['host_name']; |
| 1201 | 1233 | } |
| 1202 | 1234 | } |
| 1203 | - } |
|
| 1204 | - catch (Exception $e) |
|
| 1235 | + } catch (Exception $e) |
|
| 1205 | 1236 | { |
| 1206 | 1237 | $this->trapLog('Error in rule eval : '.$e->getMessage(),WARN,''); |
| 1207 | 1238 | $this->trap_action.=' ERR : '.$e->getMessage(); |
@@ -1212,8 +1243,7 @@ discard block |
||
| 1212 | 1243 | if ($this->trap_data['status']=='error') |
| 1213 | 1244 | { |
| 1214 | 1245 | $this->trap_to_db=true; // Always put errors in DB for the use can see |
| 1215 | - } |
|
| 1216 | - else |
|
| 1246 | + } else |
|
| 1217 | 1247 | { |
| 1218 | 1248 | $this->trap_data['status']='done'; |
| 1219 | 1249 | } |
@@ -1268,8 +1298,7 @@ discard block |
||
| 1268 | 1298 | if (preg_match('/^ *CREATE TABLE ([^ ]+)/',$newline,$cur_table_array)) |
| 1269 | 1299 | { |
| 1270 | 1300 | $cur_table='table '.$cur_table_array[1]; |
| 1271 | - } |
|
| 1272 | - else |
|
| 1301 | + } else |
|
| 1273 | 1302 | { |
| 1274 | 1303 | $cur_table='secret SQL stuff :-)'; |
| 1275 | 1304 | } |
@@ -1313,8 +1342,7 @@ discard block |
||
| 1313 | 1342 | if ($this->trapDBType == 'pgsql') |
| 1314 | 1343 | { |
| 1315 | 1344 | $prefix .= 'update_pgsql/schema_'; |
| 1316 | - } |
|
| 1317 | - else |
|
| 1345 | + } else |
|
| 1318 | 1346 | { |
| 1319 | 1347 | $prefix .= 'update_sql/schema_'; |
| 1320 | 1348 | } |
@@ -1360,7 +1388,10 @@ discard block |
||
| 1360 | 1388 | $db_conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 1361 | 1389 | while (($line=fgets($input_stream)) !== false) |
| 1362 | 1390 | { |
| 1363 | - if (preg_match('/^#/', $line)) continue; // ignore comment lines |
|
| 1391 | + if (preg_match('/^#/', $line)) { |
|
| 1392 | + continue; |
|
| 1393 | + } |
|
| 1394 | + // ignore comment lines |
|
| 1364 | 1395 | $newline.=chop(preg_replace('/#PREFIX#/',$table_prefix,$line)); |
| 1365 | 1396 | if (preg_match('/; *$/', $newline)) |
| 1366 | 1397 | { |
@@ -1372,8 +1403,7 @@ discard block |
||
| 1372 | 1403 | if (preg_match('/^ *([^ ]+) TABLE ([^ ]+)/',$newline,$cur_table_array)) |
| 1373 | 1404 | { |
| 1374 | 1405 | $cur_table=$cur_table_array[1] . ' SQL table '.$cur_table_array[2]; |
| 1375 | - } |
|
| 1376 | - else |
|
| 1406 | + } else |
|
| 1377 | 1407 | { |
| 1378 | 1408 | $cur_table='secret SQL stuff :-)'; |
| 1379 | 1409 | //$cur_table=$newline; |
@@ -1511,8 +1541,7 @@ discard block |
||
| 1511 | 1541 | } |
| 1512 | 1542 | $this->trapLog('Trap updated : '.$name . ' / OID : '.$oid,4,''); |
| 1513 | 1543 | return 1; |
| 1514 | - } |
|
| 1515 | - else |
|
| 1544 | + } else |
|
| 1516 | 1545 | { |
| 1517 | 1546 | $this->trapLog('Trap unchanged : '.$name . ' / OID : '.$oid,4,''); |
| 1518 | 1547 | return 0; |
@@ -1528,7 +1557,9 @@ discard block |
||
| 1528 | 1557 | 'values (:oid, :name , :type ,:mib ,:tc , :display_hint'. |
| 1529 | 1558 | ', :syntax, :type_enum, :description )'; |
| 1530 | 1559 | |
| 1531 | - if ($this->trapDBType == 'pgsql') $sql .= 'RETURNING id'; |
|
| 1560 | + if ($this->trapDBType == 'pgsql') { |
|
| 1561 | + $sql .= 'RETURNING id'; |
|
| 1562 | + } |
|
| 1532 | 1563 | |
| 1533 | 1564 | $sqlQuery=$db_conn->prepare($sql); |
| 1534 | 1565 | |
@@ -1568,7 +1599,9 @@ discard block |
||
| 1568 | 1599 | } |
| 1569 | 1600 | |
| 1570 | 1601 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
| 1571 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 1602 | + if ($inserted_id==false) { |
|
| 1603 | + throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 1604 | + } |
|
| 1572 | 1605 | $this->dbOidIndex[$oid]['id']=$inserted_id; |
| 1573 | 1606 | break; |
| 1574 | 1607 | default: |
@@ -1821,12 +1854,14 @@ discard block |
||
| 1821 | 1854 | $name=$match[1]; // Name |
| 1822 | 1855 | $type=$match[2]; // type (21=trap, 0: may be trap, else : not trap |
| 1823 | 1856 | |
| 1824 | - if ($type==0) // object type=0 : check if v1 trap |
|
| 1857 | + if ($type==0) { |
|
| 1858 | + // object type=0 : check if v1 trap |
|
| 1825 | 1859 | { |
| 1826 | 1860 | // Check if next is suboid -> in that case is cannot be a trap |
| 1827 | 1861 | if (preg_match("/^$oid/",$this->objectsAll[$curElement+1])) |
| 1828 | 1862 | { |
| 1829 | 1863 | $time_check2 += microtime(true) - $time_1; |
| 1864 | + } |
|
| 1830 | 1865 | $time_check2N++; |
| 1831 | 1866 | continue; |
| 1832 | 1867 | } |
@@ -1843,9 +1878,11 @@ discard block |
||
| 1843 | 1878 | // Force as trap. |
| 1844 | 1879 | $type=21; |
| 1845 | 1880 | } |
| 1846 | - if ($onlyTraps===true && $type!=21) // if only traps and not a trap, continue |
|
| 1881 | + if ($onlyTraps===true && $type!=21) { |
|
| 1882 | + // if only traps and not a trap, continue |
|
| 1847 | 1883 | { |
| 1848 | 1884 | $time_check3 += microtime(true) - $time_1; |
| 1885 | + } |
|
| 1849 | 1886 | $time_check3N++; |
| 1850 | 1887 | continue; |
| 1851 | 1888 | } |
@@ -1853,7 +1890,10 @@ discard block |
||
| 1853 | 1890 | $time_num_traps++; |
| 1854 | 1891 | |
| 1855 | 1892 | $this->trapLog('Found trap : '.$match[1] . ' / OID : '.$oid,3,''); |
| 1856 | - if ($display_progress) echo '#'; // echo a # when trap found |
|
| 1893 | + if ($display_progress) { |
|
| 1894 | + echo '#'; |
|
| 1895 | + } |
|
| 1896 | + // echo a # when trap found |
|
| 1857 | 1897 | |
| 1858 | 1898 | // get trap objects & source MIB |
| 1859 | 1899 | unset($snmptrans); |
@@ -1871,7 +1911,9 @@ discard block |
||
| 1871 | 1911 | $trapMib=$match[1]; |
| 1872 | 1912 | |
| 1873 | 1913 | $numLine=1;$trapDesc=''; |
| 1874 | - while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++; |
|
| 1914 | + while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) { |
|
| 1915 | + $numLine++; |
|
| 1916 | + } |
|
| 1875 | 1917 | if (isset($snmptrans[$numLine])) |
| 1876 | 1918 | { |
| 1877 | 1919 | $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]); |
@@ -1893,7 +1935,9 @@ discard block |
||
| 1893 | 1935 | if (($update==0) && ($check_change===false)) |
| 1894 | 1936 | { // Trapd didn't change & force check disabled |
| 1895 | 1937 | $time_objects += microtime(true) - $time_1; |
| 1896 | - if ($display_progress) echo "C"; |
|
| 1938 | + if ($display_progress) { |
|
| 1939 | + echo "C"; |
|
| 1940 | + } |
|
| 1897 | 1941 | continue; |
| 1898 | 1942 | } |
| 1899 | 1943 | |