@@ -40,8 +40,7 @@ |
||
| 40 | 40 | $query = $dataBase->select()->from($Config->getTrapRuleName(),array('COUNT(*)')); |
| 41 | 41 | printf("Number of rules : %s\n", $dataBase->fetchOne($query) ); |
| 42 | 42 | |
| 43 | - } |
|
| 44 | - catch (Exception $e) |
|
| 43 | + } catch (Exception $e) |
|
| 45 | 44 | { |
| 46 | 45 | printf('Error in DB : %s\n', $e->getMessage()); |
| 47 | 46 | } |
@@ -42,14 +42,12 @@ discard block |
||
| 42 | 42 | if ($days=='<default>') |
| 43 | 43 | { |
| 44 | 44 | $trap->eraseOldTraps(); |
| 45 | - } |
|
| 46 | - else |
|
| 45 | + } else |
|
| 47 | 46 | { |
| 48 | 47 | $trap->eraseOldTraps($days); |
| 49 | 48 | } |
| 50 | 49 | |
| 51 | - } |
|
| 52 | - catch (Exception $e) |
|
| 50 | + } catch (Exception $e) |
|
| 53 | 51 | { |
| 54 | 52 | echo 'Error in updating : ' . $e->getMessage(); |
| 55 | 53 | } |
@@ -74,8 +72,7 @@ discard block |
||
| 74 | 72 | try |
| 75 | 73 | { |
| 76 | 74 | $trap->reset_services(); |
| 77 | - } |
|
| 78 | - catch (Exception $e) |
|
| 75 | + } catch (Exception $e) |
|
| 79 | 76 | { |
| 80 | 77 | echo 'ERROR : '. $e->getMessage(); |
| 81 | 78 | } |
@@ -256,7 +256,9 @@ discard block |
||
| 256 | 256 | $first=1; |
| 257 | 257 | foreach($this->moduleConfig->getTrapListSearchColumns() as $column) |
| 258 | 258 | { |
| 259 | - if ($first==0) $sql.=' OR '; |
|
| 259 | + if ($first==0) { |
|
| 260 | + $sql.=' OR '; |
|
| 261 | + } |
|
| 260 | 262 | $first=0; |
| 261 | 263 | $sql.=" ".$column." LIKE '%".$this->filter_query."%' "; |
| 262 | 264 | } |
@@ -264,10 +266,14 @@ discard block |
||
| 264 | 266 | } |
| 265 | 267 | if ($this->filter_done == 1) |
| 266 | 268 | { |
| 267 | - if ($sql != '') $sql.=' AND '; |
|
| 269 | + if ($sql != '') { |
|
| 270 | + $sql.=' AND '; |
|
| 271 | + } |
|
| 268 | 272 | $sql.="(status != 'done')"; |
| 269 | 273 | } |
| 270 | - if ($sql != '') $query->where($sql); |
|
| 274 | + if ($sql != '') { |
|
| 275 | + $query->where($sql); |
|
| 276 | + } |
|
| 271 | 277 | return $query; |
| 272 | 278 | } |
| 273 | 279 | |
@@ -99,13 +99,11 @@ discard block |
||
| 99 | 99 | if (isset($oidName['name'])) |
| 100 | 100 | { |
| 101 | 101 | $val=$oidName['name']; |
| 102 | - } |
|
| 103 | - else |
|
| 102 | + } else |
|
| 104 | 103 | { |
| 105 | 104 | $val = $row->$rowkey; |
| 106 | 105 | } |
| 107 | - } |
|
| 108 | - else |
|
| 106 | + } else |
|
| 109 | 107 | { |
| 110 | 108 | $val = $row->$rowkey; |
| 111 | 109 | } |
@@ -114,8 +112,7 @@ discard block |
||
| 114 | 112 | if ($row->$rowkey == null) |
| 115 | 113 | { |
| 116 | 114 | $val = $row->host_group_name; |
| 117 | - } |
|
| 118 | - else |
|
| 115 | + } else |
|
| 119 | 116 | { |
| 120 | 117 | $val = $row->$rowkey; |
| 121 | 118 | } |
@@ -214,7 +214,9 @@ discard block |
||
| 214 | 214 | $first=1; |
| 215 | 215 | foreach($this->moduleConfig->getTrapListSearchColumns() as $column) |
| 216 | 216 | { |
| 217 | - if ($first==0) $sql.=' OR '; |
|
| 217 | + if ($first==0) { |
|
| 218 | + $sql.=' OR '; |
|
| 219 | + } |
|
| 218 | 220 | $first=0; |
| 219 | 221 | $sql.=" CAST(".$column." AS char(100)) LIKE '%".$this->filter_query."%' "; |
| 220 | 222 | } |
@@ -222,10 +224,14 @@ discard block |
||
| 222 | 224 | } |
| 223 | 225 | if ($this->filter_done == 1) |
| 224 | 226 | { |
| 225 | - if ($sql != '') $sql.=' AND '; |
|
| 227 | + if ($sql != '') { |
|
| 228 | + $sql.=' AND '; |
|
| 229 | + } |
|
| 226 | 230 | $sql.="(status != 'done')"; |
| 227 | 231 | } |
| 228 | - if ($sql != '') $query->where($sql); |
|
| 232 | + if ($sql != '') { |
|
| 233 | + $query->where($sql); |
|
| 234 | + } |
|
| 229 | 235 | return $query; |
| 230 | 236 | } |
| 231 | 237 | |
@@ -68,7 +68,9 @@ |
||
| 68 | 68 | switch ($outputType) |
| 69 | 69 | { |
| 70 | 70 | case 'file': |
| 71 | - if ($outputFile == null) throw new Exception("File logging without file !"); |
|
| 71 | + if ($outputFile == null) { |
|
| 72 | + throw new Exception("File logging without file !"); |
|
| 73 | + } |
|
| 72 | 74 | $this->setFile($outputFile); |
| 73 | 75 | $this->setDestination('file'); |
| 74 | 76 | break; |
@@ -64,8 +64,7 @@ discard block |
||
| 64 | 64 | if ($pid == 1) |
| 65 | 65 | { |
| 66 | 66 | $trap->setLogging($logLevel,'display'); |
| 67 | - } |
|
| 68 | - else |
|
| 67 | + } else |
|
| 69 | 68 | { // use default display TODO : if default is 'display' son process will be killed at first output.... |
| 70 | 69 | if ($pid != 0) |
| 71 | 70 | { |
@@ -74,8 +73,7 @@ discard block |
||
| 74 | 73 | fclose($file); |
| 75 | 74 | echo "OK : process $pid in bckground"; |
| 76 | 75 | return 0; |
| 77 | - } |
|
| 78 | - else |
|
| 76 | + } else |
|
| 79 | 77 | { // son process : close all file descriptors and go to a new session |
| 80 | 78 | fclose($file); |
| 81 | 79 | // $sid = posix_setsid(); |
@@ -85,8 +83,7 @@ discard block |
||
| 85 | 83 | try |
| 86 | 84 | { |
| 87 | 85 | $trap->mibClass->update_mib_database(false,$forceCheck); |
| 88 | - } |
|
| 89 | - catch (Exception $e) |
|
| 86 | + } catch (Exception $e) |
|
| 90 | 87 | { |
| 91 | 88 | $trap->trapLog('Error in updating : ' . $e->getMessage(),2); |
| 92 | 89 | } |
@@ -103,8 +100,7 @@ discard block |
||
| 103 | 100 | $trap->mibClass->update_mib_database(true,$forceCheck); |
| 104 | 101 | echo "Done\n"; |
| 105 | 102 | |
| 106 | - } |
|
| 107 | - catch (Exception $e) |
|
| 103 | + } catch (Exception $e) |
|
| 108 | 104 | { |
| 109 | 105 | echo 'Error in updating : ' . $e->getMessage(); |
| 110 | 106 | } |
@@ -147,8 +143,7 @@ discard block |
||
| 147 | 143 | $Config->getMIBCacheTableName(), |
| 148 | 144 | 'id>0'); |
| 149 | 145 | echo 'Deleted '. $query . " traps and objects\n"; |
| 150 | - } |
|
| 151 | - catch (Exception $e) |
|
| 146 | + } catch (Exception $e) |
|
| 152 | 147 | { |
| 153 | 148 | echo 'Error in DB : ' . $e->getMessage(); |
| 154 | 149 | } |
@@ -84,8 +84,7 @@ discard block |
||
| 84 | 84 | } |
| 85 | 85 | $this->logging->log('Trap updated : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG ); |
| 86 | 86 | return 1; |
| 87 | - } |
|
| 88 | - else |
|
| 87 | + } else |
|
| 89 | 88 | { |
| 90 | 89 | $this->logging->log('Trap unchanged : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG ); |
| 91 | 90 | return 0; |
@@ -107,7 +106,9 @@ discard block |
||
| 107 | 106 | 'values (:oid, :name , :type ,:mib ,:tc , :display_hint'. |
| 108 | 107 | ', :syntax, :type_enum, :description )'; |
| 109 | 108 | |
| 110 | - if ($this->trapsDB->trapDBType == 'pgsql') $sql .= 'RETURNING id'; |
|
| 109 | + if ($this->trapsDB->trapDBType == 'pgsql') { |
|
| 110 | + $sql .= 'RETURNING id'; |
|
| 111 | + } |
|
| 111 | 112 | |
| 112 | 113 | $sqlQuery=$db_conn->prepare($sql); |
| 113 | 114 | |
@@ -147,7 +148,9 @@ discard block |
||
| 147 | 148 | } |
| 148 | 149 | |
| 149 | 150 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
| 150 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 151 | + if ($inserted_id==false) { |
|
| 152 | + throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 153 | + } |
|
| 151 | 154 | $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id; |
| 152 | 155 | break; |
| 153 | 156 | default: |
@@ -325,7 +328,10 @@ discard block |
||
| 325 | 328 | $this->reset_oidDesc(); |
| 326 | 329 | |
| 327 | 330 | $snmptrans=$this->get_object_details($object, $trapmib); // Get object mib & details |
| 328 | - if ($snmptrans === null) continue; // object not found |
|
| 331 | + if ($snmptrans === null) { |
|
| 332 | + continue; |
|
| 333 | + } |
|
| 334 | + // object not found |
|
| 329 | 335 | |
| 330 | 336 | $this->parse_object($snmptrans); |
| 331 | 337 | |
@@ -476,12 +482,14 @@ discard block |
||
| 476 | 482 | $this->oidDesc['name']=$match[1]; // Name |
| 477 | 483 | $this->oidDesc['type']=$match[2]; // type (21=trap, 0: may be trap, else : not trap |
| 478 | 484 | |
| 479 | - if ($this->oidDesc['type']==0) // object type=0 : check if v1 trap |
|
| 485 | + if ($this->oidDesc['type']==0) { |
|
| 486 | + // object type=0 : check if v1 trap |
|
| 480 | 487 | { |
| 481 | 488 | // Check if next is suboid -> in that case is cannot be a trap |
| 482 | 489 | if (preg_match("/^".$this->oidDesc['oid']."/",$this->objectsAll[$curElement+1])) |
| 483 | 490 | { |
| 484 | 491 | $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time']; |
| 492 | + } |
|
| 485 | 493 | $this->timing['type0_check_num']++; |
| 486 | 494 | return true; |
| 487 | 495 | } |
@@ -499,9 +507,11 @@ discard block |
||
| 499 | 507 | // Force as trap. |
| 500 | 508 | $this->oidDesc['type']=21; |
| 501 | 509 | } |
| 502 | - if ($onlyTraps===true && $this->oidDesc['type']!=21) // if only traps and not a trap, continue |
|
| 510 | + if ($onlyTraps===true && $this->oidDesc['type']!=21) { |
|
| 511 | + // if only traps and not a trap, continue |
|
| 503 | 512 | { |
| 504 | 513 | $this->timing['nottrap_time'] += microtime(true) - $this->timing['base_time']; |
| 514 | + } |
|
| 505 | 515 | $this->timing['nottrap_num']++; |
| 506 | 516 | return true; |
| 507 | 517 | } |
@@ -532,7 +542,9 @@ discard block |
||
| 532 | 542 | $this->oidDesc['mib']=$match[1]; |
| 533 | 543 | |
| 534 | 544 | $numLine=1; |
| 535 | - while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++; |
|
| 545 | + while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) { |
|
| 546 | + $numLine++; |
|
| 547 | + } |
|
| 536 | 548 | if (isset($snmptrans[$numLine])) |
| 537 | 549 | { |
| 538 | 550 | $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]); |
@@ -636,7 +648,10 @@ discard block |
||
| 636 | 648 | $this->timing['num_traps']++; |
| 637 | 649 | |
| 638 | 650 | $this->logging->log('Found trap : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],INFO ); |
| 639 | - if ($display_progress) echo '#'; // echo a # when trap found |
|
| 651 | + if ($display_progress) { |
|
| 652 | + echo '#'; |
|
| 653 | + } |
|
| 654 | + // echo a # when trap found |
|
| 640 | 655 | |
| 641 | 656 | // get trap objects & source MIB |
| 642 | 657 | |
@@ -653,7 +668,9 @@ discard block |
||
| 653 | 668 | if (($update==0) && ($check_change===false)) |
| 654 | 669 | { // Trapd didn't change & force check disabled |
| 655 | 670 | $this->timing['objects_time'] += microtime(true) - $this->timing['base_time']; |
| 656 | - if ($display_progress) echo "C"; |
|
| 671 | + if ($display_progress) { |
|
| 672 | + echo "C"; |
|
| 673 | + } |
|
| 657 | 674 | continue; |
| 658 | 675 | } |
| 659 | 676 | |
@@ -17,8 +17,9 @@ discard block |
||
| 17 | 17 | if (! $input) { |
| 18 | 18 | $inputStream=fopen('php://stdin', 'r'); |
| 19 | 19 | $rule=chop(fgets($inputStream)); |
| 20 | -} else |
|
| 20 | +} else { |
|
| 21 | 21 | $rule=$options['r']; |
| 22 | +} |
|
| 22 | 23 | |
| 23 | 24 | try |
| 24 | 25 | { |
@@ -28,8 +29,7 @@ discard block |
||
| 28 | 29 | $val = $trap->ruleClass->evaluation($rule,$item); |
| 29 | 30 | if ($val==true) { printf( "true"); } else { printf( "false");} |
| 30 | 31 | printf("\n"); |
| 31 | -} |
|
| 32 | -catch (Exception $e) { printf("%s\n",$e->getMessage()); exit(1);} |
|
| 32 | +} catch (Exception $e) { printf("%s\n",$e->getMessage()); exit(1);} |
|
| 33 | 33 | |
| 34 | 34 | exit(0); |
| 35 | 35 | ?> |