Passed
Push — master ( ff53ce...185c6a )
by Patrick
01:57
created

Mib::reset_oidDesc()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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

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