From f97f9c824b6c0d789c9b10cff27d5575be51ee5b Mon Sep 17 00:00:00 2001 From: Ultra2D Date: Sat, 5 Mar 2016 11:59:49 +0100 Subject: [PATCH] Added syslog Procurve unit testing --- tests/SyslogTest.php | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/SyslogTest.php b/tests/SyslogTest.php index c5e35c2ee..eb25c0af7 100644 --- a/tests/SyslogTest.php +++ b/tests/SyslogTest.php @@ -141,6 +141,52 @@ class SyslogTest extends \PHPUnit_Framework_TestCase ); + // run tests + foreach($testdata as $data) { + $res = process_syslog($data['input'], 0); + $this->assertEquals($data['result'], $res); + } + } + public function testProcurveSyslog() + { + // populate fake $dev_cache and $config + global $config, $dev_cache; + $dev_cache['1.1.1.1'] = array('device_id' => 1, 'os' => 'procurve', 'version' => 1); + $config = array(); + $config['syslog_filter'] = array(); + + // populate test data + $testdata = array(); + + // ---- 2900/2910/3800/5400 ---- + $testdata[] = $this->createData( + "1.1.1.1||user||info||info||0e||2016-02-28 00:23:34||chassis: Slot A Ready||00422", + array('device_id'=>1, 'program'=>'CHASSIS', 'msg'=>'Slot A Ready [00422]') + ); + $testdata[] = $this->createData( + "1.1.1.1||user||info||info||0e||2016-02-28 00:23:34||ports: port 21 is now on-line||00076", + array('device_id'=>1, 'program'=>'PORTS', 'msg'=>'port 21 is now on-line [00076]') + ); + $testdata[] = $this->createData( + "1.1.1.1||user||info||info||0e||2016-02-28 00:23:34||ports: port 21 is now off-line||00077", + array('device_id'=>1, 'program'=>'PORTS', 'msg'=>'port 21 is now off-line [00077]') + ); + $testdata[] = $this->createData( + "1.1.1.1||user||warning||warning||0c||2016-02-28 00:23:34||FFI: port 21-High collision or drop rate. See help.||00331", + array('device_id'=>1, 'program'=>'FFI', 'msg'=>'port 21-High collision or drop rate. See help. [00331]') + ); + + // ---- 2610 ---- + $testdata[] = $this->createData( + "1.1.1.1||user||warning||warning||0c||2016-02-28 00:23:34||port 21-Excessive undersized/giant packets. See help.||FFI", + array('device_id'=>1, 'program'=>'FFI', 'msg'=>'port 21-Excessive undersized/giant packets. See help.') + ); + $testdata[] = $this->createData( + "1.1.1.1||user||info||info||0e||2016-02-28 00:23:34||updated time by -4 seconds||SNTP", + array('device_id'=>1, 'program'=>'SNTP', 'msg'=>'updated time by -4 seconds') + ); + + // run tests foreach($testdata as $data) { $res = process_syslog($data['input'], 0);