@@ -68,9 +68,9 @@ discard block |
||
| 68 | 68 | { |
| 69 | 69 | $this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile); |
| 70 | 70 | $this->logSetup=true; |
| 71 | + } else { |
|
| 72 | + $this->logSetup=false; |
|
| 71 | 73 | } |
| 72 | - else |
|
| 73 | - $this->logSetup=false; |
|
| 74 | 74 | $this->logging->log('Loggin started', INFO); |
| 75 | 75 | |
| 76 | 76 | // Get options from ini files |
@@ -83,7 +83,10 @@ discard block |
||
| 83 | 83 | $this->setupDatabase($trapConfig); // Setup database class |
| 84 | 84 | |
| 85 | 85 | $this->getDatabaseOptions(); // Get options in database |
| 86 | - if ($this->api_use === true) $this->getAPI(); // Setup API |
|
| 86 | + if ($this->api_use === true) { |
|
| 87 | + $this->getAPI(); |
|
| 88 | + } |
|
| 89 | + // Setup API |
|
| 87 | 90 | |
| 88 | 91 | $this->mibClass = new Mib($this->logging,$this->trapsDB); // Create Mib class |
| 89 | 92 | |
@@ -117,8 +120,7 @@ discard block |
||
| 117 | 120 | } |
| 118 | 121 | $this->logging->log($message,$log_level,'syslog'); |
| 119 | 122 | return false; |
| 120 | - } |
|
| 121 | - else |
|
| 123 | + } else |
|
| 122 | 124 | { |
| 123 | 125 | $option_var=$option_array[$option_category][$option_name]; |
| 124 | 126 | return true; |
@@ -182,7 +184,10 @@ discard block |
||
| 182 | 184 | |
| 183 | 185 | $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->db_prefix); |
| 184 | 186 | |
| 185 | - if ($this->api_use === true) return; // In case of API use, no IDO is necessary |
|
| 187 | + if ($this->api_use === true) { |
|
| 188 | + return; |
|
| 189 | + } |
|
| 190 | + // In case of API use, no IDO is necessary |
|
| 186 | 191 | |
| 187 | 192 | // IDO Database |
| 188 | 193 | if (!array_key_exists('IDOdatabase',$trapConfig['config'])) |
@@ -207,9 +212,11 @@ discard block |
||
| 207 | 212 | protected function getDatabaseOptions() |
| 208 | 213 | { |
| 209 | 214 | // Database options |
| 210 | - if ($this->logSetup === false) // Only if logging was no setup in constructor |
|
| 215 | + if ($this->logSetup === false) { |
|
| 216 | + // Only if logging was no setup in constructor |
|
| 211 | 217 | { |
| 212 | 218 | $this->getDBConfigIfSet('log_level',$this->logging->debugLevel); |
| 219 | + } |
|
| 213 | 220 | $this->getDBConfigIfSet('log_destination',$this->logging->outputMode); |
| 214 | 221 | $this->getDBConfigIfSet('log_file',$this->logging->outputFile); |
| 215 | 222 | } |
@@ -218,7 +225,9 @@ discard block |
||
| 218 | 225 | protected function getDBConfigIfSet($element,&$variable) |
| 219 | 226 | { |
| 220 | 227 | $value=$this->getDBConfig($element); |
| 221 | - if ($value != 'null') $variable=$value; |
|
| 228 | + if ($value != 'null') { |
|
| 229 | + $variable=$value; |
|
| 230 | + } |
|
| 222 | 231 | } |
| 223 | 232 | |
| 224 | 233 | /** |
@@ -306,8 +315,7 @@ discard block |
||
| 306 | 315 | { |
| 307 | 316 | $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)"); |
| 308 | 317 | $this->logging->log('Error parsing IP : '.$IP,ERROR,''); |
| 309 | - } |
|
| 310 | - else |
|
| 318 | + } else |
|
| 311 | 319 | { |
| 312 | 320 | $this->trap_data['source_ip']=$matches[1]; |
| 313 | 321 | $this->trap_data['destination_ip']=$matches[3]; |
@@ -322,14 +330,12 @@ discard block |
||
| 322 | 330 | if ($ret_code===0 || $ret_code===false) |
| 323 | 331 | { |
| 324 | 332 | $this->logging->log('No match on trap data : '.$vars,WARN,''); |
| 325 | - } |
|
| 326 | - else |
|
| 333 | + } else |
|
| 327 | 334 | { |
| 328 | 335 | 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')) |
| 329 | 336 | { |
| 330 | 337 | $this->trap_data['trap_oid']=$matches[2]; |
| 331 | - } |
|
| 332 | - else |
|
| 338 | + } else |
|
| 333 | 339 | { |
| 334 | 340 | $object= new stdClass; |
| 335 | 341 | $object->oid =$matches[1]; |
@@ -500,7 +506,9 @@ discard block |
||
| 500 | 506 | } |
| 501 | 507 | |
| 502 | 508 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
| 503 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 509 | + if ($inserted_id==false) { |
|
| 510 | + throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 511 | + } |
|
| 504 | 512 | $this->trap_id=$inserted_id; |
| 505 | 513 | break; |
| 506 | 514 | default: |
@@ -516,7 +524,9 @@ discard block |
||
| 516 | 524 | { |
| 517 | 525 | |
| 518 | 526 | // If action is ignore -> don't send t DB |
| 519 | - if ($this->trap_to_db === false) return; |
|
| 527 | + if ($this->trap_to_db === false) { |
|
| 528 | + return; |
|
| 529 | + } |
|
| 520 | 530 | |
| 521 | 531 | |
| 522 | 532 | $db_conn=$this->trapsDB->db_connect_trap(); |
@@ -573,7 +583,9 @@ discard block |
||
| 573 | 583 | } |
| 574 | 584 | |
| 575 | 585 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
| 576 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 586 | + if ($inserted_id==false) { |
|
| 587 | + throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 588 | + } |
|
| 577 | 589 | $this->trap_id=$inserted_id; |
| 578 | 590 | break; |
| 579 | 591 | default: |
@@ -702,8 +714,7 @@ discard block |
||
| 702 | 714 | // TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default.... |
| 703 | 715 | exec('echo "'.$send.'" > ' .$this->icinga2cmd); |
| 704 | 716 | return true; |
| 705 | - } |
|
| 706 | - else |
|
| 717 | + } else |
|
| 707 | 718 | { |
| 708 | 719 | $api = $this->getAPI(); |
| 709 | 720 | $api->setCredentials($this->api_username, $this->api_password); |
@@ -712,8 +723,7 @@ discard block |
||
| 712 | 723 | { |
| 713 | 724 | $this->logging->log( "Error sending result : " .$retmessage,WARN,''); |
| 714 | 725 | return false; |
| 715 | - } |
|
| 716 | - else |
|
| 726 | + } else |
|
| 717 | 727 | { |
| 718 | 728 | $this->logging->log( "Sent result : " .$retmessage,INFO ); |
| 719 | 729 | return true; |
@@ -773,7 +783,9 @@ discard block |
||
| 773 | 783 | /***************** Eval & tokenizer functions ****************/ |
| 774 | 784 | protected function eval_getElement($rule,&$item) |
| 775 | 785 | { |
| 776 | - while ($rule[$item]==' ') $item++; |
|
| 786 | + while ($rule[$item]==' ') { |
|
| 787 | + $item++; |
|
| 788 | + } |
|
| 777 | 789 | if (preg_match('/[0-9\.]/',$rule[$item])) |
| 778 | 790 | { // number |
| 779 | 791 | |
@@ -800,14 +812,15 @@ discard block |
||
| 800 | 812 | $start=$item; |
| 801 | 813 | $parenthesis_count=0; |
| 802 | 814 | while (($item < strlen($rule)) // Not end of string AND |
| 803 | - && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded () |
|
| 815 | + && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) { |
|
| 816 | + // Closing ')' or embeded () |
|
| 804 | 817 | { |
| 805 | 818 | if ($rule[$item] == '"' ) |
| 806 | 819 | { // pass through string |
| 807 | 820 | $item++; |
| 821 | + } |
|
| 808 | 822 | $item=$this->eval_getNext($rule,$item,'"'); |
| 809 | - } |
|
| 810 | - else{ |
|
| 823 | + } else{ |
|
| 811 | 824 | if ($rule[$item] == '(') |
| 812 | 825 | { |
| 813 | 826 | $parenthesis_count++; |
@@ -835,13 +848,17 @@ discard block |
||
| 835 | 848 | protected function eval_getNext($rule,$item,$tok) |
| 836 | 849 | { |
| 837 | 850 | while (($rule[$item] != $tok ) && ($item < strlen($rule))) { $item++;} |
| 838 | - if ($item==strlen($rule)) throw new Exception("closing '".$tok."' not found in ".$rule ." at " .$item); |
|
| 851 | + if ($item==strlen($rule)) { |
|
| 852 | + throw new Exception("closing '".$tok."' not found in ".$rule ." at " .$item); |
|
| 853 | + } |
|
| 839 | 854 | return $item+1; |
| 840 | 855 | } |
| 841 | 856 | |
| 842 | 857 | protected function eval_getOper($rule,&$item) |
| 843 | 858 | { |
| 844 | - while ($rule[$item]==' ') $item++; |
|
| 859 | + while ($rule[$item]==' ') { |
|
| 860 | + $item++; |
|
| 861 | + } |
|
| 845 | 862 | switch ($rule[$item]) |
| 846 | 863 | { |
| 847 | 864 | case '<': |
@@ -877,12 +894,13 @@ discard block |
||
| 877 | 894 | public function evaluation($rule,&$item) |
| 878 | 895 | { |
| 879 | 896 | //echo "Evaluation of ".substr($rule,$item)."\n"; |
| 880 | - if ( $rule[$item] == '!') // If '!' found, negate next expression. |
|
| 897 | + if ( $rule[$item] == '!') { |
|
| 898 | + // If '!' found, negate next expression. |
|
| 881 | 899 | { |
| 882 | 900 | $negate=true; |
| 883 | - $item++; |
|
| 884 | 901 | } |
| 885 | - else |
|
| 902 | + $item++; |
|
| 903 | + } else |
|
| 886 | 904 | { |
| 887 | 905 | $negate=false; |
| 888 | 906 | } |
@@ -890,10 +908,14 @@ discard block |
||
| 890 | 908 | list($type1,$val1) = $this->eval_getElement($rule,$item); |
| 891 | 909 | //echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n"; |
| 892 | 910 | |
| 893 | - if ($item==strlen($rule)) // If only element, return value, but only boolean |
|
| 911 | + if ($item==strlen($rule)) { |
|
| 912 | + // If only element, return value, but only boolean |
|
| 894 | 913 | { |
| 895 | 914 | if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule); |
| 896 | - if ($negate === true) $val1= ! $val1; |
|
| 915 | + } |
|
| 916 | + if ($negate === true) { |
|
| 917 | + $val1= ! $val1; |
|
| 918 | + } |
|
| 897 | 919 | return $val1; |
| 898 | 920 | } |
| 899 | 921 | |
@@ -902,27 +924,34 @@ discard block |
||
| 902 | 924 | //echo "Comp : ".$comp." : ".substr($rule,$item)."\n"; |
| 903 | 925 | |
| 904 | 926 | // Third element : number, string or () |
| 905 | - if ( $rule[$item] == '!') // starts with a ! so evaluate whats next |
|
| 927 | + if ( $rule[$item] == '!') { |
|
| 928 | + // starts with a ! so evaluate whats next |
|
| 906 | 929 | { |
| 907 | 930 | $item++; |
| 908 | - if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule); |
|
| 931 | + } |
|
| 932 | + if ($typec != 1) { |
|
| 933 | + throw new Exception("Mixing boolean and comparison : ".$rule); |
|
| 934 | + } |
|
| 909 | 935 | $val2= ! $this->evaluation($rule,$item); |
| 910 | 936 | $type2=2; // result is a boolean |
| 911 | - } |
|
| 912 | - else |
|
| 937 | + } else |
|
| 913 | 938 | { |
| 914 | 939 | list($type2,$val2) = $this->eval_getElement($rule,$item); |
| 915 | 940 | } |
| 916 | 941 | //echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n"; |
| 917 | 942 | |
| 918 | - if ($type1!=$type2) // cannot compare different types |
|
| 943 | + if ($type1!=$type2) { |
|
| 944 | + // cannot compare different types |
|
| 919 | 945 | { |
| 920 | 946 | throw new Exception("Cannot compare string & number : ".$rule); |
| 921 | 947 | } |
| 922 | - if ($typec==1 && $type1 !=2) // cannot use & or | with string/number |
|
| 948 | + } |
|
| 949 | + if ($typec==1 && $type1 !=2) { |
|
| 950 | + // cannot use & or | with string/number |
|
| 923 | 951 | { |
| 924 | 952 | throw new Exception("Cannot use boolean operators with string & number : ".$rule); |
| 925 | 953 | } |
| 954 | + } |
|
| 926 | 955 | |
| 927 | 956 | switch ($comp){ |
| 928 | 957 | case '<': $retVal= ($val1 < $val2); break; |
@@ -936,9 +965,15 @@ discard block |
||
| 936 | 965 | case '&': $retVal= ($val1 && $val2); break; |
| 937 | 966 | default: throw new Exception("Error in expression - unknown comp : ".$comp); |
| 938 | 967 | } |
| 939 | - if ($negate === true) $retVal = ! $retVal; // Inverse result if negate before expression |
|
| 968 | + if ($negate === true) { |
|
| 969 | + $retVal = ! $retVal; |
|
| 970 | + } |
|
| 971 | + // Inverse result if negate before expression |
|
| 940 | 972 | |
| 941 | - if ($item==strlen($rule)) return $retVal; // End of string : return evaluation |
|
| 973 | + if ($item==strlen($rule)) { |
|
| 974 | + return $retVal; |
|
| 975 | + } |
|
| 976 | + // End of string : return evaluation |
|
| 942 | 977 | // check for logical operator : |
| 943 | 978 | switch ($rule[$item]) |
| 944 | 979 | { |
@@ -965,7 +1000,9 @@ discard block |
||
| 965 | 1000 | $rule2.=$rule[$item]; |
| 966 | 1001 | $item++; |
| 967 | 1002 | } |
| 968 | - if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
| 1003 | + if ($item == strlen ($rule)) { |
|
| 1004 | + throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
| 1005 | + } |
|
| 969 | 1006 | $rule2.=$rule[$item]; |
| 970 | 1007 | $item++; |
| 971 | 1008 | continue; |
@@ -985,10 +1022,12 @@ discard block |
||
| 985 | 1022 | |
| 986 | 1023 | protected function eval_rule($rule) |
| 987 | 1024 | { |
| 988 | - if ($rule==null || $rule == '') // Empty rule is always true |
|
| 1025 | + if ($rule==null || $rule == '') { |
|
| 1026 | + // Empty rule is always true |
|
| 989 | 1027 | { |
| 990 | 1028 | return true; |
| 991 | 1029 | } |
| 1030 | + } |
|
| 992 | 1031 | $matches=array(); |
| 993 | 1032 | while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1) |
| 994 | 1033 | { |
@@ -1075,20 +1114,17 @@ discard block |
||
| 1075 | 1114 | if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false) |
| 1076 | 1115 | { |
| 1077 | 1116 | $this->trap_action.='Error sending status : check cmd/API'; |
| 1078 | - } |
|
| 1079 | - else |
|
| 1117 | + } else |
|
| 1080 | 1118 | { |
| 1081 | 1119 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
| 1082 | 1120 | $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name; |
| 1083 | 1121 | } |
| 1084 | - } |
|
| 1085 | - else |
|
| 1122 | + } else |
|
| 1086 | 1123 | { |
| 1087 | 1124 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
| 1088 | 1125 | } |
| 1089 | 1126 | $this->trap_to_db=($action==-2)?false:true; |
| 1090 | - } |
|
| 1091 | - else |
|
| 1127 | + } else |
|
| 1092 | 1128 | { |
| 1093 | 1129 | //$this->logging->log('rules KOO : '.print_r($rule),INFO ); |
| 1094 | 1130 | |
@@ -1099,14 +1135,12 @@ discard block |
||
| 1099 | 1135 | if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false) |
| 1100 | 1136 | { |
| 1101 | 1137 | $this->trap_action.='Error sending status : check cmd/API'; |
| 1102 | - } |
|
| 1103 | - else |
|
| 1138 | + } else |
|
| 1104 | 1139 | { |
| 1105 | 1140 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
| 1106 | 1141 | $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name; |
| 1107 | 1142 | } |
| 1108 | - } |
|
| 1109 | - else |
|
| 1143 | + } else |
|
| 1110 | 1144 | { |
| 1111 | 1145 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
| 1112 | 1146 | } |
@@ -1116,16 +1150,14 @@ discard block |
||
| 1116 | 1150 | if (!isset($this->trap_data['source_name'])) |
| 1117 | 1151 | { |
| 1118 | 1152 | $this->trap_data['source_name']=$rule['host_name']; |
| 1119 | - } |
|
| 1120 | - else |
|
| 1153 | + } else |
|
| 1121 | 1154 | { |
| 1122 | 1155 | if (!preg_match('/'.$rule['host_name'].'/',$this->trap_data['source_name'])) |
| 1123 | 1156 | { // only add if not present |
| 1124 | 1157 | $this->trap_data['source_name'].=','.$rule['host_name']; |
| 1125 | 1158 | } |
| 1126 | 1159 | } |
| 1127 | - } |
|
| 1128 | - catch (Exception $e) |
|
| 1160 | + } catch (Exception $e) |
|
| 1129 | 1161 | { |
| 1130 | 1162 | $this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,''); |
| 1131 | 1163 | $this->trap_action.=' ERR : '.$e->getMessage(); |
@@ -1136,8 +1168,7 @@ discard block |
||
| 1136 | 1168 | if ($this->trap_data['status']=='error') |
| 1137 | 1169 | { |
| 1138 | 1170 | $this->trap_to_db=true; // Always put errors in DB for the use can see |
| 1139 | - } |
|
| 1140 | - else |
|
| 1171 | + } else |
|
| 1141 | 1172 | { |
| 1142 | 1173 | $this->trap_data['status']='done'; |
| 1143 | 1174 | } |
@@ -1273,8 +1304,7 @@ discard block |
||
| 1273 | 1304 | } |
| 1274 | 1305 | $this->logging->log('Trap updated : '.$name . ' / OID : '.$oid,DEBUG ); |
| 1275 | 1306 | return 1; |
| 1276 | - } |
|
| 1277 | - else |
|
| 1307 | + } else |
|
| 1278 | 1308 | { |
| 1279 | 1309 | $this->logging->log('Trap unchanged : '.$name . ' / OID : '.$oid,DEBUG ); |
| 1280 | 1310 | return 0; |
@@ -1290,7 +1320,9 @@ discard block |
||
| 1290 | 1320 | 'values (:oid, :name , :type ,:mib ,:tc , :display_hint'. |
| 1291 | 1321 | ', :syntax, :type_enum, :description )'; |
| 1292 | 1322 | |
| 1293 | - if ($this->trapsDB->trapDBType == 'pgsql') $sql .= 'RETURNING id'; |
|
| 1323 | + if ($this->trapsDB->trapDBType == 'pgsql') { |
|
| 1324 | + $sql .= 'RETURNING id'; |
|
| 1325 | + } |
|
| 1294 | 1326 | |
| 1295 | 1327 | $sqlQuery=$db_conn->prepare($sql); |
| 1296 | 1328 | |
@@ -1330,7 +1362,9 @@ discard block |
||
| 1330 | 1362 | } |
| 1331 | 1363 | |
| 1332 | 1364 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
| 1333 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 1365 | + if ($inserted_id==false) { |
|
| 1366 | + throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 1367 | + } |
|
| 1334 | 1368 | $this->dbOidIndex[$oid]['id']=$inserted_id; |
| 1335 | 1369 | break; |
| 1336 | 1370 | default: |
@@ -1583,12 +1617,14 @@ discard block |
||
| 1583 | 1617 | $name=$match[1]; // Name |
| 1584 | 1618 | $type=$match[2]; // type (21=trap, 0: may be trap, else : not trap |
| 1585 | 1619 | |
| 1586 | - if ($type==0) // object type=0 : check if v1 trap |
|
| 1620 | + if ($type==0) { |
|
| 1621 | + // object type=0 : check if v1 trap |
|
| 1587 | 1622 | { |
| 1588 | 1623 | // Check if next is suboid -> in that case is cannot be a trap |
| 1589 | 1624 | if (preg_match("/^$oid/",$this->objectsAll[$curElement+1])) |
| 1590 | 1625 | { |
| 1591 | 1626 | $time_check2 += microtime(true) - $time_1; |
| 1627 | + } |
|
| 1592 | 1628 | $time_check2N++; |
| 1593 | 1629 | continue; |
| 1594 | 1630 | } |
@@ -1605,9 +1641,11 @@ discard block |
||
| 1605 | 1641 | // Force as trap. |
| 1606 | 1642 | $type=21; |
| 1607 | 1643 | } |
| 1608 | - if ($onlyTraps===true && $type!=21) // if only traps and not a trap, continue |
|
| 1644 | + if ($onlyTraps===true && $type!=21) { |
|
| 1645 | + // if only traps and not a trap, continue |
|
| 1609 | 1646 | { |
| 1610 | 1647 | $time_check3 += microtime(true) - $time_1; |
| 1648 | + } |
|
| 1611 | 1649 | $time_check3N++; |
| 1612 | 1650 | continue; |
| 1613 | 1651 | } |
@@ -1615,7 +1653,10 @@ discard block |
||
| 1615 | 1653 | $time_num_traps++; |
| 1616 | 1654 | |
| 1617 | 1655 | $this->logging->log('Found trap : '.$match[1] . ' / OID : '.$oid,INFO ); |
| 1618 | - if ($display_progress) echo '#'; // echo a # when trap found |
|
| 1656 | + if ($display_progress) { |
|
| 1657 | + echo '#'; |
|
| 1658 | + } |
|
| 1659 | + // echo a # when trap found |
|
| 1619 | 1660 | |
| 1620 | 1661 | // get trap objects & source MIB |
| 1621 | 1662 | unset($snmptrans); |
@@ -1633,7 +1674,9 @@ discard block |
||
| 1633 | 1674 | $trapMib=$match[1]; |
| 1634 | 1675 | |
| 1635 | 1676 | $numLine=1;$trapDesc=''; |
| 1636 | - while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++; |
|
| 1677 | + while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) { |
|
| 1678 | + $numLine++; |
|
| 1679 | + } |
|
| 1637 | 1680 | if (isset($snmptrans[$numLine])) |
| 1638 | 1681 | { |
| 1639 | 1682 | $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]); |
@@ -1655,7 +1698,9 @@ discard block |
||
| 1655 | 1698 | if (($update==0) && ($check_change===false)) |
| 1656 | 1699 | { // Trapd didn't change & force check disabled |
| 1657 | 1700 | $time_objects += microtime(true) - $time_1; |
| 1658 | - if ($display_progress) echo "C"; |
|
| 1701 | + if ($display_progress) { |
|
| 1702 | + echo "C"; |
|
| 1703 | + } |
|
| 1659 | 1704 | continue; |
| 1660 | 1705 | } |
| 1661 | 1706 | |
@@ -171,8 +171,7 @@ discard block |
||
| 171 | 171 | if (preg_match('/^ *CREATE TABLE ([^ ]+)/',$newline,$cur_table_array)) |
| 172 | 172 | { |
| 173 | 173 | $cur_table='table '.$cur_table_array[1]; |
| 174 | - } |
|
| 175 | - else |
|
| 174 | + } else |
|
| 176 | 175 | { |
| 177 | 176 | $cur_table='secret SQL stuff :-)'; |
| 178 | 177 | } |
@@ -217,8 +216,7 @@ discard block |
||
| 217 | 216 | if ($this->trapDBType == 'pgsql') |
| 218 | 217 | { |
| 219 | 218 | $prefix .= 'update_pgsql/schema_'; |
| 220 | - } |
|
| 221 | - else |
|
| 219 | + } else |
|
| 222 | 220 | { |
| 223 | 221 | $prefix .= 'update_sql/schema_'; |
| 224 | 222 | } |
@@ -264,7 +262,10 @@ discard block |
||
| 264 | 262 | $db_conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 265 | 263 | while (($line=fgets($input_stream)) !== false) |
| 266 | 264 | { |
| 267 | - if (preg_match('/^#/', $line)) continue; // ignore comment lines |
|
| 265 | + if (preg_match('/^#/', $line)) { |
|
| 266 | + continue; |
|
| 267 | + } |
|
| 268 | + // ignore comment lines |
|
| 268 | 269 | $newline.=chop(preg_replace('/#PREFIX#/',$table_prefix,$line)); |
| 269 | 270 | if (preg_match('/; *$/', $newline)) |
| 270 | 271 | { |
@@ -276,8 +277,7 @@ discard block |
||
| 276 | 277 | if (preg_match('/^ *([^ ]+) TABLE ([^ ]+)/',$newline,$cur_table_array)) |
| 277 | 278 | { |
| 278 | 279 | $cur_table=$cur_table_array[1] . ' SQL table '.$cur_table_array[2]; |
| 279 | - } |
|
| 280 | - else |
|
| 280 | + } else |
|
| 281 | 281 | { |
| 282 | 282 | $cur_table='secret SQL stuff :-)'; |
| 283 | 283 | //$cur_table=$newline; |
@@ -82,8 +82,7 @@ discard block |
||
| 82 | 82 | } |
| 83 | 83 | $this->logging->log('Trap updated : '.$name . ' / OID : '.$oid,DEBUG ); |
| 84 | 84 | return 1; |
| 85 | - } |
|
| 86 | - else |
|
| 85 | + } else |
|
| 87 | 86 | { |
| 88 | 87 | $this->logging->log('Trap unchanged : '.$name . ' / OID : '.$oid,DEBUG ); |
| 89 | 88 | return 0; |
@@ -99,7 +98,9 @@ discard block |
||
| 99 | 98 | 'values (:oid, :name , :type ,:mib ,:tc , :display_hint'. |
| 100 | 99 | ', :syntax, :type_enum, :description )'; |
| 101 | 100 | |
| 102 | - if ($this->trapsDB->trapDBType == 'pgsql') $sql .= 'RETURNING id'; |
|
| 101 | + if ($this->trapsDB->trapDBType == 'pgsql') { |
|
| 102 | + $sql .= 'RETURNING id'; |
|
| 103 | + } |
|
| 103 | 104 | |
| 104 | 105 | $sqlQuery=$db_conn->prepare($sql); |
| 105 | 106 | |
@@ -139,7 +140,9 @@ discard block |
||
| 139 | 140 | } |
| 140 | 141 | |
| 141 | 142 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
| 142 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 143 | + if ($inserted_id==false) { |
|
| 144 | + throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 145 | + } |
|
| 143 | 146 | $this->dbOidIndex[$oid]['id']=$inserted_id; |
| 144 | 147 | break; |
| 145 | 148 | default: |
@@ -392,12 +395,14 @@ discard block |
||
| 392 | 395 | $name=$match[1]; // Name |
| 393 | 396 | $type=$match[2]; // type (21=trap, 0: may be trap, else : not trap |
| 394 | 397 | |
| 395 | - if ($type==0) // object type=0 : check if v1 trap |
|
| 398 | + if ($type==0) { |
|
| 399 | + // object type=0 : check if v1 trap |
|
| 396 | 400 | { |
| 397 | 401 | // Check if next is suboid -> in that case is cannot be a trap |
| 398 | 402 | if (preg_match("/^$oid/",$this->objectsAll[$curElement+1])) |
| 399 | 403 | { |
| 400 | 404 | $time_check2 += microtime(true) - $time_1; |
| 405 | + } |
|
| 401 | 406 | $time_check2N++; |
| 402 | 407 | continue; |
| 403 | 408 | } |
@@ -414,9 +419,11 @@ discard block |
||
| 414 | 419 | // Force as trap. |
| 415 | 420 | $type=21; |
| 416 | 421 | } |
| 417 | - if ($onlyTraps===true && $type!=21) // if only traps and not a trap, continue |
|
| 422 | + if ($onlyTraps===true && $type!=21) { |
|
| 423 | + // if only traps and not a trap, continue |
|
| 418 | 424 | { |
| 419 | 425 | $time_check3 += microtime(true) - $time_1; |
| 426 | + } |
|
| 420 | 427 | $time_check3N++; |
| 421 | 428 | continue; |
| 422 | 429 | } |
@@ -424,7 +431,10 @@ discard block |
||
| 424 | 431 | $time_num_traps++; |
| 425 | 432 | |
| 426 | 433 | $this->logging->log('Found trap : '.$match[1] . ' / OID : '.$oid,INFO ); |
| 427 | - if ($display_progress) echo '#'; // echo a # when trap found |
|
| 434 | + if ($display_progress) { |
|
| 435 | + echo '#'; |
|
| 436 | + } |
|
| 437 | + // echo a # when trap found |
|
| 428 | 438 | |
| 429 | 439 | // get trap objects & source MIB |
| 430 | 440 | unset($snmptrans); |
@@ -442,7 +452,9 @@ discard block |
||
| 442 | 452 | $trapMib=$match[1]; |
| 443 | 453 | |
| 444 | 454 | $numLine=1;$trapDesc=''; |
| 445 | - while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++; |
|
| 455 | + while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) { |
|
| 456 | + $numLine++; |
|
| 457 | + } |
|
| 446 | 458 | if (isset($snmptrans[$numLine])) |
| 447 | 459 | { |
| 448 | 460 | $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]); |
@@ -464,7 +476,9 @@ discard block |
||
| 464 | 476 | if (($update==0) && ($check_change===false)) |
| 465 | 477 | { // Trapd didn't change & force check disabled |
| 466 | 478 | $time_objects += microtime(true) - $time_1; |
| 467 | - if ($display_progress) echo "C"; |
|
| 479 | + if ($display_progress) { |
|
| 480 | + echo "C"; |
|
| 481 | + } |
|
| 468 | 482 | continue; |
| 469 | 483 | } |
| 470 | 484 | |