Passed
Push — master ( 037a61...ff53ce )
by Patrick
02:47 queued 10s
created

Mib::detect_trap()   B

Complexity

Conditions 8
Paths 8

Size

Total Lines 55
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 33
c 1
b 0
f 0
nc 8
nop 5
dl 0
loc 55
rs 8.1475

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Trapdirector;
4
5
use Trapdirector\Logging;
6
use Trapdirector\Database;
7
use PDO;
8
use Exception;
9
10
class Mib
11
{
12
    
13
    protected $logging; //< logging class
14
    protected $trapsDB; //< Database class
15
    
16
    public $snmptranslate;
17
    public $snmptranslate_dirs;
18
    
19
    private $dbOidAll; //< All oid in database;
20
    private $dbOidIndex; //< Index of oid in dbOidAll
21
    private $objectsAll; //< output lines of snmptranslate list
22
    private $trapObjectsIndex; //< array of traps objects (as OID)
23
    
24
    private $oidDesc=array(); //< $oid,$mib,$name,$type,$textConv,$dispHint,$syntax,$type_enum,$description=NULL
0 ignored issues
show
introduced by
The private property $oidDesc is not used, and could be removed.
Loading history...
25
    
26
    // Timing vars for update
27
    private $timing=array();
28
    
29
    /**
30
     * Setup Mib Class
31
     * @param Logging $logClass : where to log
32
     * @param Database $dbClass : Database
33
     */
34
    function __construct($logClass,$dbClass,$snmptrans,$snmptransdir)
35
    {
36
        $this->logging=$logClass;
37
        $this->trapsDB=$dbClass;
38
        $this->snmptranslate=$snmptrans;
39
        $this->snmptranslate_dirs=$snmptransdir;
40
41
    }
42
    
43
    
44
    /**
45
     * Update or add an OID to database uses $this->dbOidIndex for mem cache
46
     * @param string $oid
47
     * @param string $mib
48
     * @param string $name
49
     * @param string $type
50
     * @param string $textConv
51
     * @param string $dispHint
52
     * @param string $syntax
53
     * @param string $type_enum
54
     * @param string $description
55
     * @return number : 0=unchanged, 1 = changed, 2=created
56
     */
57
    public function update_oid($oid,$mib,$name,$type,$textConv,$dispHint,$syntax,$type_enum,$description=NULL)
58
    {
59
        $db_conn=$this->trapsDB->db_connect_trap();
60
        $description=$db_conn->quote($description);
61
        if (isset($this->dbOidIndex[$oid]))
62
        {
63
            if ($this->dbOidIndex[$oid]['key'] == -1)
64
            { // newly created.
65
                return 0;
66
            }
67
            if ( $name != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['name'] ||
68
                $mib != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['mib'] ||
69
                $type != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['type'] //||
70
                //$textConv != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['textual_convention'] //||
71
                //$dispHint != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['display_hint'] ||
72
                //$syntax != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['syntax'] ||
73
                //$type_enum != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['type_enum'] ||
74
                //$description != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['description']
75
                )
76
            { // Do update
77
                $sql='UPDATE '.$this->trapsDB->dbPrefix.'mib_cache SET '.
78
                    'name = :name , type = :type , mib = :mib , textual_convention = :tc , display_hint = :display_hint'.
79
                    ', syntax = :syntax, type_enum = :type_enum, description = :description '.
80
                    ' WHERE id= :id';
81
                $sqlQuery=$db_conn->prepare($sql);
82
                
83
                $sqlParam=array(
84
                    ':name' => $name,
85
                    ':type' => $type,
86
                    ':mib' => $mib,
87
                    ':tc' =>  ($textConv==null)?'null':$textConv ,
88
                    ':display_hint' => ($dispHint==null)?'null':$dispHint ,
89
                    ':syntax' => ($syntax==null)?'null':$syntax,
90
                    ':type_enum' => ($type_enum==null)?'null':$type_enum,
91
                    ':description' => ($description==null)?'null':$description,
92
                    ':id' => $this->dbOidAll[$this->dbOidIndex[$oid]['id']]
93
                );
94
                
95
                if ($sqlQuery->execute($sqlParam) === false) {
96
                    $this->logging->log('Error in query : ' . $sql,ERROR,'');
97
                }
98
                $this->logging->log('Trap updated : '.$name . ' / OID : '.$oid,DEBUG );
99
                return 1;
100
            }
101
            else
102
            {
103
                $this->logging->log('Trap unchanged : '.$name . ' / OID : '.$oid,DEBUG );
104
                return 0;
105
            }
106
        }
107
        // create new OID.
108
        
109
        // Insert data
110
        
111
        $sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache '.
112
            '(oid, name, type , mib, textual_convention, display_hint '.
113
            ', syntax, type_enum , description ) ' .
114
            'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
115
            ', :syntax, :type_enum, :description )';
116
        
117
        if ($this->trapsDB->trapDBType == 'pgsql') $sql .= 'RETURNING id';
118
        
119
        $sqlQuery=$db_conn->prepare($sql);
120
        
121
        $sqlParam=array(
122
            ':oid' => $oid,
123
            ':name' => $name,
124
            ':type' => $type,
125
            ':mib' => $mib,
126
            ':tc' =>  ($textConv==null)?'null':$textConv ,
127
            ':display_hint' => ($dispHint==null)?'null':$dispHint ,
128
            ':syntax' => ($syntax==null)?'null':$syntax,
129
            ':type_enum' => ($type_enum==null)?'null':$type_enum,
130
            ':description' => ($description==null)?'null':$description
131
        );
132
        
133
        if ($sqlQuery->execute($sqlParam) === false) {
134
            $this->logging->log('Error in query : ' . $sql,1,'');
135
        }
136
        
137
        switch ($this->trapsDB->trapDBType)
138
        {
139
            case 'pgsql':
140
                // Get last id to insert oid/values in secondary table
141
                if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) {
142
                    $this->logging->log('Error getting id - pgsql - ',1,'');
143
                }
144
                if (! isset($inserted_id_ret['id'])) {
145
                    $this->logging->log('Error getting id - pgsql - empty.',1,'');
146
                }
147
                $this->dbOidIndex[$oid]['id']=$inserted_id_ret['id'];
148
                break;
149
            case 'mysql':
150
                // Get last id to insert oid/values in secondary table
151
                $sql='SELECT LAST_INSERT_ID();';
152
                if (($ret_code=$db_conn->query($sql)) === false) {
153
                    $this->logging->log('Erreur getting id - mysql - ',1,'');
154
                }
155
                
156
                $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
157
                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
158
                $this->dbOidIndex[$oid]['id']=$inserted_id;
159
                break;
160
            default:
161
                $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType,1,'');
162
        }
163
        
164
        // Set as newly created.
165
        $this->dbOidIndex[$oid]['key']=-1;
166
        return 2;
167
    }
168
    
169
    /**
170
     * create or update (with check_existing = true) objects of trap
171
     * @param string $trapOID : trap oid
172
     * @param string $trapmib : mib of trap
173
     * @param array $objects : array of objects name (without MIB)
174
     * @param bool $check_existing : check instead of create
175
     */
176
    public function trap_objects($trapOID,$trapmib,$objects,$check_existing)
177
    {
178
        $dbObjects=null; // cache of objects for trap in db
179
        $db_conn=$this->trapsDB->db_connect_trap();
180
        
181
        // Get id of trapmib.
182
        
183
        $trapId = $this->dbOidIndex[$trapOID]['id'];
184
        if ($check_existing === true)
185
        {
186
            // Get all objects
187
            $sql='SELECT * FROM '.$this->trapsDB->dbPrefix.'mib_cache_trap_object where trap_id='.$trapId.';';
188
            $this->logging->log('SQL query get all traps: '.$sql,DEBUG );
189
            if (($ret_code=$db_conn->query($sql)) === false) {
190
                $this->logging->log('No result in query : ' . $sql,1,'');
191
            }
192
            $dbObjectsRaw=$ret_code->fetchAll();
193
            
194
            foreach ($dbObjectsRaw as $val)
195
            {
196
                $dbObjects[$val['object_id']]=1;
197
            }
198
        }
199
        foreach ($objects as $object)
200
        {
201
            $match=$snmptrans=array();
202
            $retVal=0;
203
            $objOid=$objTc=$objDispHint=$objSyntax=$objDesc=$objEnum=NULL;
204
            $tmpdesc='';$indesc=false;
205
            
206
            $objMib=$trapmib;
207
            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
208
                ' -On -Td '.$objMib.'::'.$object . ' 2>/dev/null',$snmptrans,$retVal);
209
            if ($retVal!=0)
210
            {
211
                // Maybe not trap mib, search with IR
212
                exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
213
                    ' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal);
214
                if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match))
215
                { // Not found -> continue with warning
216
                    $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object,2,'');
217
                    continue;
218
                }
219
                $objMib=$match[1];
220
                
221
                // Do the snmptranslate again.
222
                exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
223
                    ' -On -Td '.$objMib.'::'.$object,$snmptrans,$retVal);
224
                if ($retVal!=0) {
225
                    $this->logging->log('Error finding trap object : '.$objMib.'::'.$object,2,'');
226
                }
227
                
228
            }
229
            foreach ($snmptrans as $line)
230
            {
231
                if ($indesc===true)
232
                {
233
                    $line=preg_replace('/[\t ]+/',' ',$line);
234
                    if (preg_match('/(.*)"$/', $line,$match))
235
                    {
236
                        $objDesc = $tmpdesc . $match[1];
237
                        $indesc=false;
238
                    }
239
                    $tmpdesc.=$line;
240
                    continue;
241
                }
242
                if (preg_match('/^\.[0-9\.]+$/', $line))
243
                {
244
                    $objOid=$line;
245
                    continue;
246
                }
247
                if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match))
248
                {
249
                    $objSyntax=$match[1];
250
                    $objEnum=$match[2];
251
                    continue;
252
                }
253
                if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match))
254
                {
255
                    $objSyntax=$match[1];
256
                    continue;
257
                }
258
                if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match))
259
                {
260
                    $objDispHint=$match[1];
261
                    continue;
262
                }
263
                if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match))
264
                {
265
                    $objDesc=$match[1];
266
                    continue;
267
                }
268
                if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match))
269
                {
270
                    $tmpdesc=$match[1];
271
                    $indesc=true;
272
                    continue;
273
                }
274
                if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match))
275
                {
276
                    $objTc=$match[1];
277
                    continue;
278
                }
279
            }
280
            $this->logging->log("Adding trap $object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc",DEBUG );
281
            //echo "$object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc / $objDesc\n";
282
            // Update
283
            $this->update_oid($objOid, $objMib, $object, '3', $objTc, $objDispHint, $objSyntax, $objEnum,$objDesc);
284
            
285
            if (isset($dbObjects[$this->dbOidIndex[$objOid]['id']]))
286
            {   // if link exists, continue
287
                $dbObjects[$this->dbOidIndex[$objOid]['id']]=2;
288
                continue;
289
            }
290
            if ($check_existing === true)
291
            {
292
                // TODO : check link trap - objects exists, mark them.
293
            }
294
            // Associate in object table
295
            $sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache_trap_object (trap_id,object_id) '.
296
                'values (:trap_id, :object_id)';
297
            $sqlQuery=$db_conn->prepare($sql);
298
            $sqlParam=array(
299
                ':trap_id' => $trapId,
300
                ':object_id' => $this->dbOidIndex[$objOid]['id'],
301
            );
302
            
303
            if ($sqlQuery->execute($sqlParam) === false) {
304
                $this->logging->log('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$objOid]['id'] ,1,'');
305
            }
306
        }
307
        if ($check_existing === true)
308
        {
309
            // TODO : remove link trap - objects that wasn't marked.
310
        }
311
        
312
    }
313
    
314
    /**
315
     * Fills $this->objectsAll with all mibs from snmptranslate
316
     * @return integer : number of elements 
317
     */
318
    private function load_mibs_snmptranslate()
319
    {
320
        $retVal=0;
321
        // Get all mib objects from all mibs
322
        $snmpCommand=$this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.' -On -Tto 2>/dev/null';
323
        $this->logging->log('Getting all traps : '.$snmpCommand,DEBUG );
324
        unset($this->objectsAll);
325
        exec($snmpCommand,$this->objectsAll,$retVal);
326
        if ($retVal!=0)
327
        {
328
            $this->logging->log('error executing snmptranslate',ERROR,'');
329
        }
330
        // Count elements to show progress
331
        $numElements=count($this->objectsAll);
332
        $this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements,INFO );
333
        return $numElements;
334
    }
335
336
    /**
337
     * load all mib objects db in dbOidAll (raw) and index in dbOidIndex
338
     */
339
    private function load_mibs_from_db()
340
    {
341
        // Get all mibs from databse to have a memory index
342
        
343
        $db_conn=$this->trapsDB->db_connect_trap();
344
        
345
        $sql='SELECT * from '.$this->trapsDB->dbPrefix.'mib_cache;';
346
        $this->logging->log('SQL query : '.$sql,DEBUG );
347
        if (($ret_code=$db_conn->query($sql)) === false) {
348
            $this->logging->log('No result in query : ' . $sql,ERROR,'');
349
        }
350
        $this->dbOidAll=$ret_code->fetchAll();
351
        $this->dbOidIndex=array();
352
        // Create the index for db;
353
        foreach($this->dbOidAll as $key=>$val)
354
        {
355
            $this->dbOidIndex[$val['oid']]['key']=$key;
356
            $this->dbOidIndex[$val['oid']]['id']=$val['id'];
357
        }
358
    }
359
360
    /**
361
     * Reset all update timers & count to zero
362
     */
363
    private function reset_update_timers()
364
    {
365
        $this->timing['base_parse_time']=$this->timing['base_check_time']=0;
366
        $this->timing['type0_check_time']=$this->timing['nottrap_time']=0;
367
        $this->timing['update_time']=$this->timing['objects_time']=0;
368
        $this->timing['base_parse_num']=$this->timing['base_check_num']=0;
369
        $this->timing['type0_check_num']=$this->timing['nottrap_num']=0;
370
        $this->timing['update_num']=$this->timing['objects_num']=0;
371
        $this->timing['num_traps']=0;
372
    }
373
374
    private function detect_trap($curElement,$onlyTraps,&$name,&$type,&$oid)
375
    {
376
        // Get oid or pass if not found
377
        if (!preg_match('/^\.[0-9\.]+$/',$this->objectsAll[$curElement]))
378
        {
379
            $this->timing['base_parse_time'] += microtime(true) - $this->timing['base_time'];
380
            $this->timing['base_parse_num'] ++;
381
            return true;
382
        }
383
        $oid=$this->objectsAll[$curElement];
384
        
385
        // get next line
386
        $curElement++;
387
        $match=$snmptrans=array();
388
        if (!preg_match('/ +([^\(]+)\(.+\) type=([0-9]+)( tc=([0-9]+))?( hint=(.+))?/',
389
            $this->objectsAll[$curElement],$match))
390
        {
391
            $this->timing['base_check_time'] += microtime(true) - $this->timing['base_time'];
392
            $this->timing['base_check_num']++;
393
            return true;
394
        }
395
        
396
        $name=$match[1]; // Name
397
        $type=$match[2]; // type (21=trap, 0: may be trap, else : not trap
398
        
399
        if ($type==0) // object type=0 : check if v1 trap
400
        {
401
            // Check if next is suboid -> in that case is cannot be a trap
402
            if (preg_match("/^$oid/",$this->objectsAll[$curElement+1]))
403
            {
404
                $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
405
                $this->timing['type0_check_num']++;
406
                return true;
407
            }
408
            unset($snmptrans);
409
            $retVal=0;
410
            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
411
                ' -Td '.$oid . ' | grep OBJECTS ',$snmptrans,$retVal);
412
            if ($retVal!=0)
413
            {
414
                $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
415
                $this->timing['type0_check_num']++;
416
                return true;
417
            }
418
            //echo "\n v1 trap found : $oid \n";
419
            // Force as trap.
420
            $type=21;
421
        }
422
        if ($onlyTraps===true && $type!=21) // if only traps and not a trap, continue
423
        {
424
            $this->timing['nottrap_time'] += microtime(true) - $this->timing['base_time'];
425
            $this->timing['nottrap_num']++;
426
            return true;
427
        }
428
        return false;
429
    }
430
    
431
    /**
432
     * Cache mib in database
433
     * @param boolean $display_progress : Display progress on standard output
434
     * @param boolean $check_change : Force check of trap params & objects
435
     * @param boolean $onlyTraps : only cache traps and objects (true) or all (false)
436
     * @param string $startOID : only cache under startOID (NOT IMPLEMENTED)
437
     */
438
    public function update_mib_database($display_progress=false,$check_change=false,$onlyTraps=true,$startOID='.1')
0 ignored issues
show
Unused Code introduced by
The parameter $startOID is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

438
    public function update_mib_database($display_progress=false,$check_change=false,$onlyTraps=true,/** @scrutinizer ignore-unused */ $startOID='.1')

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
439
    {
440
        // Global Timing
441
        $timeTaken = microtime(true);
442
        
443
        $numElements=$this->load_mibs_snmptranslate(); // Load objectsAll
444
        
445
        $this->load_mibs_from_db(); // Load from db dbOidAll & dbOidIndex
446
        
447
        $step=$basestep=$numElements/10; // output display of % done
448
        $num_step=0;
449
        $timeFiveSec = microtime(true); // Used for display a '.' every <n> seconds
450
        
451
        // Create index for trap objects
452
        $this->trapObjectsIndex=array();
453
        
454
        // detailed timing (time_* vars)
455
        $this->reset_update_timers();
456
        
457
        for ($curElement=0;$curElement < $numElements;$curElement++)
458
        {
459
            $this->timing['base_time']= microtime(true);
460
            if ((microtime(true)-$timeFiveSec) > 2 && $display_progress)
461
            { // echo a . every 2 sec
462
                echo '.';
463
                $timeFiveSec = microtime(true);
464
            }
465
            if ($curElement>$step)
466
            { // display progress
467
                $num_step++;
468
                $step+=$basestep;
469
                if ($display_progress)
470
                {
471
                    echo "\n" . ($num_step*10). '% : ';
472
                }
473
            }
474
            $name=$type=$oid='';
475
            if ($this->detect_trap($curElement,$onlyTraps,$name,$type,$oid)===true)
476
            {
477
                continue;
478
            }
479
            
480
            $this->timing['num_traps']++;
481
            
482
            $this->logging->log('Found trap : '.$name . ' / OID : '.$oid,INFO );
483
            if ($display_progress) echo '#'; // echo a # when trap found
484
            
485
            // get trap objects & source MIB
486
            $retVal=0;
487
            $match=$snmptrans=array();
488
            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
489
                ' -Td '.$oid,$snmptrans,$retVal);
490
            if ($retVal!=0)
491
            {
492
                $this->logging->log('error executing snmptranslate',ERROR,'');
493
            }
494
            
495
            if (!preg_match('/^(.*)::/',$snmptrans[0],$match))
496
            {
497
                $this->logging->log('Error getting mib from trap '.$oid.' : ' . $snmptrans[0],1,'');
498
            }
499
            $trapMib=$match[1];
500
            
501
            $numLine=1;$trapDesc='';
502
            while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++;
503
            if (isset($snmptrans[$numLine]))
504
            {
505
                $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
506
                
507
                while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine]))
508
                {
509
                    $trapDesc.=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]);
510
                    $numLine++;
511
                }
512
                if (isset($snmptrans[$numLine])) {
513
                    $trapDesc.=preg_replace('/".*/','',$snmptrans[$numLine]);
514
                    $trapDesc=preg_replace('/[\t ]+/',' ',$trapDesc);
515
                }
516
                
517
            }
518
            $update=$this->update_oid($oid,$trapMib,$name,$type,NULL,NULL,NULL,NULL,$trapDesc);
519
            $this->timing['update_time'] += microtime(true) - $this->timing['base_time'];
520
            $this->timing['update_num']++;
521
            
522
            $this->timing['base_time']= microtime(true); // Reset to check object time
523
            
524
            if (($update==0) && ($check_change===false))
525
            { // Trapd didn't change & force check disabled
526
                $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
527
                if ($display_progress) echo "C";
528
                continue;
529
            }
530
            
531
            $synt=null;
532
            foreach ($snmptrans as $line)
533
            {
534
                if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match))
535
                {
536
                    $synt=$match[1];
537
                }
538
            }
539
            if ($synt == null)
540
            {
541
                //echo "No objects for $trapOID\n";
542
                $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
543
                continue;
544
            }
545
            //echo "$synt \n";
546
            $trapObjects=array();
547
            while (preg_match('/ *([^ ,]+) *,* */',$synt,$match))
548
            {
549
                array_push($trapObjects,$match[1]);
550
                $synt=preg_replace('/'.$match[0].'/','',$synt);
551
            }
552
            
553
            $this->trap_objects($oid, $trapMib, $trapObjects, false);
554
            
555
            $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
556
            $this->timing['objects_num']++;
557
        }
558
        
559
        if ($display_progress)
560
        {
561
            echo "\nNumber of processed traps :  ". $this->timing['num_traps'] ."\n";
562
            echo "\nParsing : " . number_format($this->timing['base_parse_time']+$this->timing['base_check_time'],1) ." sec / " . ($this->timing['base_parse_num']+ $this->timing['base_check_num'])  . " occurences\n";
563
            echo "Detecting traps : " . number_format($this->timing['type0_check_time']+$this->timing['nottrap_time'],1) . " sec / " . ($this->timing['type0_check_num']+$this->timing['nottrap_num']) ." occurences\n";
564
            echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'],1)." sec , ";
565
            echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'],1)." sec \n";
566
        }
567
        
568
        // Timing ends
569
        $timeTaken=microtime(true) - $timeTaken;
570
        if ($display_progress)
571
        {
572
            echo "Global time : ".round($timeTaken)." seconds\n";
573
        }
574
        
575
    }
576
    
577
    
578
}