Commit version 24.12.13800

This commit is contained in:
2025-01-06 17:35:06 -05:00
parent b7f6a79c2c
commit 55d9218816
6133 changed files with 4239740 additions and 1374287 deletions

View File

@ -1,6 +1,6 @@
<?php
include(__DIR__ . '/../includes/sql-config.inc.php'); // Here required DB connect
include(__DIR__ . '/../includes/observium.inc.php'); // Here required DB connect
//include(dirname(__FILE__) . '/../includes/defaults.inc.php');
//include(dirname(__FILE__) . '/../config.php');
//include(dirname(__FILE__) . '/../includes/definitions.inc.php');
@ -10,8 +10,9 @@ include(__DIR__ . '/../html/includes/functions.inc.php');
class HtmlIncludesFunctionsTest extends \PHPUnit\Framework\TestCase
{
/**
* @dataProvider providerNiceCase
*/
* @dataProvider providerNiceCase
* @group string
*/
public function testNiceCase($string, $result)
{
$this->assertSame($result, nicecase($string));
@ -62,46 +63,165 @@ class HtmlIncludesFunctionsTest extends \PHPUnit\Framework\TestCase
);
}
/**
* @dataProvider providerGetDeviceIcon
* @group device
*/
public function testGetDeviceIcon($device, $base_icon, $result)
{
$GLOBALS['config']['base_url'] = 'http://localhost';
$this->assertSame($result, get_device_icon($device, $base_icon));
}
/**
* @dataProvider providerGetDeviceIcon
* @group icon
*/
public function testGetDeviceIcon($device, $base_icon, $result) {
$GLOBALS['config']['base_url'] = 'http://localhost';
// for device_permitted
$device['device_id'] = 98217;
$_SESSION['userlevel'] = 7;
$this->assertSame($result, get_device_icon($device, $base_icon));
}
public function providerGetDeviceIcon() {
return [
// by $device['os']
[ [ 'os' => 'screenos', 'icon' => '', 'sysObjectID' => '' ], TRUE, 'juniper-old' ],
// by $device['os'] and icon definition
[ [ 'os' => 'ios', 'icon' => '', 'sysObjectID' => '' ], TRUE, 'cisco' ],
// by $device['os'] and vendor definition
[ [ 'os' => 'liebert', 'icon' => '', 'sysObjectID' => '' ], TRUE, 'emerson' ],
// by $device['os'] and vendor defined icon
[ [ 'os' => 'summitd-wl', 'icon' => '', 'sysObjectID' => '' ], TRUE, 'summitd' ],
// by $device['os'] and vendor defined icon
[ [ 'os' => 'summitd-wl', 'icon' => '', 'sysObjectID' => '', 'vendor' => 'Summit Development' ], TRUE, 'summitd' ],
// by $device['os'] and vendor definition (with non alpha chars)
[ [ 'os' => 'wut-com' ], TRUE, 'wut' ], // W&T
// by $device['os'] and distro name in array
[ [ 'os' => 'linux', 'icon' => '', 'sysObjectID' => '', 'distro' => 'RedHat' ], TRUE, 'redhat' ],
// by $device['os'] and icon in device array
[ [ 'os' => 'ios', 'icon' => 'cisco-old', 'sysObjectID' => '' ], TRUE, 'cisco-old' ],
// by all, who win?
[ [ 'os' => 'liebert', 'distro' => 'RedHat', 'icon' => 'cisco-old', 'sysObjectID' => '' ], TRUE, 'cisco-old' ],
// unknown
[ [ 'os' => 'yohoho', 'icon' => '', 'sysObjectID' => '' ], TRUE, 'generic' ],
// empty
[ [], TRUE, 'generic' ],
// Prevent use vendor icon for unix/window oses and visa-versa for others
[ [ 'os' => 'pve', 'type' => 'hypervisor', 'sysObjectID' => '', 'vendor' => 'Supermicro' ], TRUE, 'proxmox' ],
[ [ 'os' => 'proxmox-server', 'type' => 'server', 'sysObjectID' => '', 'vendor' => 'Supermicro' ], TRUE, 'proxmox' ],
[ [ 'os' => 'truenas-core', 'type' => 'storage', 'sysObjectID' => '', 'vendor' => 'Supermicro' ], TRUE, 'truenas' ],
[ [ 'os' => 'generic-ups', 'type' => 'power', 'sysObjectID' => '', 'vendor' => '' ], TRUE, 'ups' ],
[ [ 'os' => 'generic-ups', 'type' => 'power', 'sysObjectID' => '', 'vendor' => 'Supermicro' ], TRUE, 'supermicro' ],
// Last, check with img tag
[ [ 'os' => 'ios' ], FALSE, '<img src="http://localhost/images/os/cisco.svg" style="max-height: 32px; max-width: 48px;" alt="" />' ],
[ [ 'os' => 'screenos' ], FALSE, '<img src="http://localhost/images/os/juniper-old.png" srcset="http://localhost/images/os/juniper-old_2x.png 2x" alt="" />' ],
];
}
protected function setUp(): void
{
// Start the session before each test
@session_start();
}
protected function tearDown(): void
{
// Clean up the session after each test
session_unset();
session_destroy();
}
/**
* @group session
*/
public function test_single_key()
{
session_set_var('key', 'value');
$this->assertEquals('value', $_SESSION['key']);
}
/**
* @group session
*/
public function test_nested_keys()
{
session_set_var('key1->key2->key3', 'value');
$this->assertEquals('value', $_SESSION['key1']['key2']['key3']);
}
/**
* @group session
*/
public function test_unset_single_key()
{
$_SESSION['key'] = 'value';
session_set_var('key', null);
$this->assertArrayNotHasKey('key', $_SESSION);
}
/**
* @group session
*/
public function test_unset_nested_keys()
{
$_SESSION['key1']['key2']['key3'] = 'value';
session_set_var('key1->key2->key3', null);
$this->assertArrayNotHasKey('key3', $_SESSION['key1']['key2']);
}
/**
* @group session
*/
public function test_no_change_single_key()
{
$_SESSION['key'] = 'value';
session_set_var('key', 'value');
$this->assertEquals('value', $_SESSION['key']);
}
/**
* @group session
*/
public function test_no_change_nested_keys()
{
$_SESSION['key1']['key2']['key3'] = 'value';
session_set_var('key1->key2->key3', 'value');
$this->assertEquals('value', $_SESSION['key1']['key2']['key3']);
}
/**
* @group session
*/
public function test_single_key_array()
{
session_set_var(['key'], 'value');
$this->assertEquals('value', $_SESSION['key']);
}
/**
* @group session
*/
public function test_nested_keys_array()
{
session_set_var(['key1', 'key2', 'key3'], 'value');
$this->assertEquals('value', $_SESSION['key1']['key2']['key3']);
}
/**
* @group session
*/
public function test_unset_single_key_array()
{
$_SESSION['key'] = 'value';
session_set_var(['key'], null);
$this->assertArrayNotHasKey('key', $_SESSION);
}
/**
* @group session
*/
public function test_unset_nested_keys_array()
{
$_SESSION['key1']['key2']['key3'] = 'value';
session_set_var(['key1', 'key2', 'key3'], null);
$this->assertArrayNotHasKey('key3', $_SESSION['key1']['key2']);
}
public function providerGetDeviceIcon()
{
return array(
// by $device['os']
array(array('os' => 'screenos', 'icon' => '', 'sysObjectID' => ''), TRUE, 'juniper-old'),
// by $device['os'] and icon definition
array(array('os' => 'ios', 'icon' => '', 'sysObjectID' => ''), TRUE, 'cisco'),
// by $device['os'] and vendor definition
array(array('os' => 'cyclades', 'icon' => '', 'sysObjectID' => ''), TRUE, 'emerson'),
// by $device['os'] and vendor defined icon
array(array('os' => 'summitd-wl', 'icon' => '', 'sysObjectID' => ''), TRUE, 'summitd'),
// by $device['os'] and vendor defined icon
array(array('os' => 'summitd-wl', 'icon' => '', 'sysObjectID' => '', 'vendor' => 'Summit Development'), TRUE, 'summitd'),
// by $device['os'] and vendor definition (with non alpha chars)
//array(array('os' => 'ccplus'), TRUE, 'c_c_power'),
// by $device['os'] and distro name in array
array(array('os' => 'linux', 'icon' => '', 'sysObjectID' => '', 'distro' => 'RedHat'), TRUE, 'redhat'),
// by $device['os'] and icon in array
array(array('os' => 'ios', 'icon' => 'cisco-old', 'sysObjectID' => ''), TRUE, 'cisco-old'),
// by all, who win?
array(array('os' => 'cyclades', 'distro' => 'RedHat', 'icon' => 'cisco-old', 'sysObjectID' => ''), TRUE, 'cisco-old'),
// unknown
array(array('os' => 'yohoho', 'icon' => '', 'sysObjectID' => ''), TRUE, 'generic'),
// empty
array(array(), TRUE, 'generic'),
// Last, check with img tag
array(array('os' => 'ios'), FALSE, '<img src="http://localhost/images/os/cisco.png" srcset="http://localhost/images/os/cisco_2x.png 2x" alt="" />'),
);
}
}
// EOF

View File

@ -4,7 +4,11 @@ $base_dir = realpath(__DIR__ . '/..');
$config['install_dir'] = $base_dir;
include(__DIR__ . '/../includes/defaults.inc.php');
//include(dirname(__FILE__) . '/../config.php');
//include(dirname(__FILE__) . '/../config.php'); // Do not include user editable config here
include(__DIR__ . "/../includes/polyfill.inc.php");
include(__DIR__ . "/../includes/autoloader.inc.php");
include(__DIR__ . "/../includes/debugging.inc.php");
require_once(__DIR__ ."/../includes/constants.inc.php");
include(__DIR__ . '/../includes/common.inc.php');
include(__DIR__ . '/../includes/definitions.inc.php');
include(__DIR__ . '/../includes/functions.inc.php');
@ -47,7 +51,7 @@ class HtmlIncludesPrintTest extends \PHPUnit\Framework\TestCase
<th style="width: 20px;"></th>
<th style="width: 150px;"><a href="routing/protocol=bgp/type=all/sort=peer_ip/">Peer address</a></th>
<th style="width: 50px;"><a href="routing/protocol=bgp/type=all/sort=type/">Type</a></th>
<th >Family</th>
<th>Family</th>
<th><a href="routing/protocol=bgp/type=all/sort=peer_as/">Remote AS</a></th>
<th><a href="routing/protocol=bgp/type=all/sort=state/">State</a></th>
<th>Uptime / Updates</th>
@ -64,8 +68,8 @@ class HtmlIncludesPrintTest extends \PHPUnit\Framework\TestCase
<th style="width: 150px;"><a href="routing/protocol=bgp/type=all/sort=device/">Local address</a></th>
<th style="width: 20px;"></th>
<th style="width: 150px;"><a href="routing/protocol=bgp/type=all/sort=peer_ip/">Peer address</a></th>
<th style="width: 50px;"><a href="routing/protocol=bgp/type=all/sort=type/sort_order=desc/">Type&nbsp;&nbsp;<i class="small glyphicon glyphicon-triangle-bottom"></i></a></th>
<th >Family</th>
<th style="width: 50px;"><a href="routing/protocol=bgp/type=all/sort=type/sort_order=desc/"><span class="text-primary" style="font-style: italic">Type</span>&nbsp;<i class="text-primary small glyphicon glyphicon-arrow-up"></i></a></th>
<th>Family</th>
<th><a href="routing/protocol=bgp/type=all/sort=peer_as/">Remote AS</a></th>
<th><a href="routing/protocol=bgp/type=all/sort=state/">State</a></th>
<th>Uptime / Updates</th>
@ -83,7 +87,7 @@ class HtmlIncludesPrintTest extends \PHPUnit\Framework\TestCase
<th style="width: 20px;"></th>
<th style="width: 150px;">Peer address</th>
<th style="width: 50px;">Type</th>
<th >Family</th>
<th>Family</th>
<th>Remote AS</th>
<th>State</th>
<th>Uptime / Updates</th>
@ -94,6 +98,198 @@ class HtmlIncludesPrintTest extends \PHPUnit\Framework\TestCase
);
}
/**
* @dataProvider providerGenerateTableHeader
* @group common
*/
public function testGenerateTableHeader($cols, $result, $vars = [])
{
$this->assertSame($result, generate_table_header($cols, $vars));
}
public function providerGenerateTableHeader()
{
$ports_basic = [
'state-marker' => '',
[ NULL, 'style' => "width: 1px;" ],
'device' => [ 'device' => 'Device', 'style' => "min-width: 150px;"],
[ 'port' => 'Port Name', 'descr' => 'Description', 'errors' => 'Errors', 'style' => "min-width: 250px;"],
[ 'traffic' => [ 'Bits', 'subfields' => [ 'traffic_in' => 'In', 'traffic_out' => 'Out' ] ], 'style' => "width: 100px;" ],
[ 'traffic_perc' => [ '%', 'subfields' => [ 'traffic_perc_in' => 'In', 'traffic_perc_out' => 'Out' ] ], 'style' => "width: 110px;" ],
[ 'packets' => [ 'Pkts', 'subfields' => [ 'packets_in' => 'In', 'packets_out' => 'Out' ] ], 'style' => "width: 90px;" ],
[ 'speed' => 'Speed', 'mtu' => 'MTU', 'style' => "width: 90px;" ],
[ 'media' => 'Media', 'mac' => 'MAC', 'style' => "width: 150px;" ]
];
$ports_detail = [
'state-marker' => '',
[ NULL, 'style' => "width: 1px;" ],
'device' => [ 'device' => 'Device', 'style' => "min-width: 150px;" ],
[ 'port' => 'Port Name', 'descr' => 'Description', 'errors' => 'Errors', 'style' => "min-width: 250px;" ],
[ NULL ],
[ 'traffic' => [ 'Bits', 'subfields' => [ 'traffic_in' => 'In', 'traffic_out' => 'Out' ] ],
'packets' => [ 'Pkts', 'subfields' => [ 'packets_in' => 'In', 'packets_out' => 'Out' ] ], 'style' => "width: 100px;" ],
[ 'media' => "Media", 'speed' => 'Speed' ],
[ 'mac' => "MAC" ],
];
$ports_detail2 = [
'state-marker' => '',
[ NULL, 'style' => "width: 1px;" ],
[ 'device' => 'Device', 'style' => "min-width: 150px;" ],
[ 'port' => 'Port Name', 'descr' => 'Description', 'errors' => 'Errors', 'style' => "min-width: 250px;" ],
[ NULL ],
[ 'traffic' => [ 'Bits', 'subfields' => [ 'traffic_in' => 'In', 'traffic_out' => 'Out' ] ],
'packets' => [ 'Pkts', 'subfields' => [ 'packets_in' => 'In', 'packets_out' => 'Out' ] ], 'style' => "width: 100px;" ],
[ 'media' => "Media", 'speed' => 'Speed' ],
[ 'mac' => "MAC" ],
];
$mixed = [
'class' => 'header',
'style' => 'width: 100%;',
'state-marker' => '',
[ 'Date', 'style' => 'width: 150px;' ],
[ 'user' => 'User' ],
[ 'from' => 'From' ],
[ 'User-Agent', 'style' => 'width: 200px;' ],
[ 'Action', 'Test' ],
];
$array = [];
$array[] = [
$ports_basic,
' <thead>
<tr>
<th class="state-marker"></th>
<th style="width: 1px;"></th>
<th style="min-width: 150px;"><a href="ports/format=list/view=basic/sort=device/">Device</a></th>
<th style="min-width: 250px;"><a href="ports/format=list/view=basic/sort=port/">Port Name</a> / <a href="ports/format=list/view=basic/sort=descr/">Description</a> / <a href="ports/format=list/view=basic/sort=errors/">Errors</a></th>
<th style="width: 100px;"><a href="ports/format=list/view=basic/sort=traffic/">Bits</a> [<a href="ports/format=list/view=basic/sort=traffic_in/">In</a> / <a href="ports/format=list/view=basic/sort=traffic_out/">Out</a>]</th>
<th style="width: 110px;"><a href="ports/format=list/view=basic/sort=traffic_perc/">%</a> [<a href="ports/format=list/view=basic/sort=traffic_perc_in/">In</a> / <a href="ports/format=list/view=basic/sort=traffic_perc_out/">Out</a>]</th>
<th style="width: 90px;"><a href="ports/format=list/view=basic/sort=packets/">Pkts</a> [<a href="ports/format=list/view=basic/sort=packets_in/">In</a> / <a href="ports/format=list/view=basic/sort=packets_out/">Out</a>]</th>
<th style="width: 90px;"><a href="ports/format=list/view=basic/sort=speed/">Speed</a> / <a href="ports/format=list/view=basic/sort=mtu/">MTU</a></th>
<th style="width: 150px;"><a href="ports/format=list/view=basic/sort=media/">Media</a> / <a href="ports/format=list/view=basic/sort=mac/">MAC</a></th>
</tr>
</thead>
',
[ 'page' => 'ports', 'format' => 'list', 'view' => 'basic' ]
];
$array[] = [
$ports_detail,
' <thead>
<tr>
<th class="state-marker"></th>
<th style="width: 1px;"></th>
<th style="min-width: 150px;"><a href="ports/format=list/view=detail/sort=device/">Device</a></th>
<th style="min-width: 250px;"><a href="ports/format=list/view=detail/sort=port/">Port Name</a> / <a href="ports/format=list/view=detail/sort=descr/">Description</a> / <a href="ports/format=list/view=detail/sort=errors/">Errors</a></th>
<th></th>
<th style="width: 100px;"><a href="ports/format=list/view=detail/sort=traffic/">Bits</a> [<a href="ports/format=list/view=detail/sort=traffic_in/">In</a> / <a href="ports/format=list/view=detail/sort=traffic_out/">Out</a>] / <a href="ports/format=list/view=detail/sort=packets/">Pkts</a> [<a href="ports/format=list/view=detail/sort=packets_in/">In</a> / <a href="ports/format=list/view=detail/sort=packets_out/">Out</a>]</th>
<th><a href="ports/format=list/view=detail/sort=media/">Media</a> / <a href="ports/format=list/view=detail/sort=speed/">Speed</a></th>
<th><a href="ports/format=list/view=detail/sort=mac/">MAC</a></th>
</tr>
</thead>
',
[ 'page' => 'ports', 'format' => 'list', 'view' => 'detail' ]
];
$array[] = [
$ports_detail2,
' <thead>
<tr>
<th class="state-marker"></th>
<th style="width: 1px;"></th>
<th style="min-width: 150px;"><a href="ports/format=list/view=detail/sort=device/">Device</a></th>
<th style="min-width: 250px;"><a href="ports/format=list/view=detail/sort=port/">Port Name</a> / <a href="ports/format=list/view=detail/sort=descr/">Description</a> / <a href="ports/format=list/view=detail/sort=errors/">Errors</a></th>
<th></th>
<th style="width: 100px;"><a href="ports/format=list/view=detail/sort=traffic/">Bits</a> [<a href="ports/format=list/view=detail/sort=traffic_in/">In</a> / <a href="ports/format=list/view=detail/sort=traffic_out/">Out</a>] / <a href="ports/format=list/view=detail/sort=packets/">Pkts</a> [<a href="ports/format=list/view=detail/sort=packets_in/">In</a> / <a href="ports/format=list/view=detail/sort=packets_out/">Out</a>]</th>
<th><a href="ports/format=list/view=detail/sort=media/">Media</a> / <a href="ports/format=list/view=detail/sort=speed/">Speed</a></th>
<th><a href="ports/format=list/view=detail/sort=mac/">MAC</a></th>
</tr>
</thead>
',
[ 'page' => 'ports', 'format' => 'list', 'view' => 'detail' ]
];
$array[] = [
$mixed,
' <thead class="header" style="width: 100%;">
<tr>
<th class="state-marker"></th>
<th style="width: 150px;">Date</th>
<th><a href="/sort=user/">User</a></th>
<th><a href="/sort=from/">From</a></th>
<th style="width: 200px;">User-Agent</th>
<th>Action / Test</th>
</tr>
</thead>
',
[ TRUE ] // just not empty vars
];
$array[] = [
$mixed,
' <thead class="header" style="line-height: 0; visibility: collapse;">
<tr>
<th class="state-marker"></th>
<th style="width: 150px;">Date</th>
<th><a href="/sort=user/">User</a></th>
<th><a href="/sort=from/">From</a></th>
<th style="width: 200px;">User-Agent</th>
<th>Action / Test</th>
</tr>
</thead>
',
[ 'show_header' => 0 ]
];
$array[] = [
$mixed,
' <thead class="header" style="width: 100%;">
<tr>
<th class="state-marker"></th>
<th style="width: 150px;">Date</th>
<th>User</th>
<th>From</th>
<th style="width: 200px;">User-Agent</th>
<th>Action / Test</th>
</tr>
</thead>
',
[ 'show_sort' => 0 ]
];
return $array;
}
/**
* @dataProvider providerGenerateButtonGroup
* @group common
*/
public function testGenerateButtonGroup($buttons, $opts, $result)
{
$this->assertSame($result, generate_button_group($buttons, $opts));
}
public function providerGenerateButtonGroup()
{
return [
[
[
[ 'title' => 'Edit', 'event' => 'default', 'url' => '#modal-edit_syslog_rule_' . $la['la_id'], 'icon' => 'icon-cog text-muted', 'attribs' => [ 'data-toggle' => 'modal' ] ],
[ 'title' => 'Delete', 'event' => 'danger', 'url' => '#modal-delete_syslog_rule_' . $la['la_id'], 'icon' => 'icon-trash', 'attribs' => [ 'data-toggle' => 'modal' ] ],
],
[ 'title' => 'Rule actions' ],
' <div class="btn-group btn-group-xs" role="group" aria-label="Rule actions">
<a role="group" class="btn btn-default" title="Edit" href="#modal-edit_syslog_rule_"data-toggle="modal"><i class="icon-cog text-muted "></i></a>
<a role="group" class="btn btn-danger" title="Delete" href="#modal-delete_syslog_rule_"data-toggle="modal"><i class="icon-trash "></i></a>
</div>' . PHP_EOL
],
];
}
/**
* @dataProvider providerGetForm
* @group forms
@ -318,7 +514,8 @@ FORM;
<div id="remember_div" class="control-group" style="margin-bottom: 5px;"> <!-- START row-2 -->
<div id="remember_div" class="controls">
<input type="checkbox" name="remember" id="remember" value="1" /> <label for="remember" class="help-inline" style="margin-top: 4px;"><span style="min-width: 150px;">Remember my login</span></label>
<input type="checkbox" name="remember" id="remember" value="1" />
<label for="remember" class="help-inline" style="margin-top: 4px;"><span style="min-width: 150px;">Remember my login</span></label>
</div>
</div> <!-- END row-2 -->
@ -362,6 +559,10 @@ FORM;
$array[] = [ 'Please read [FAQ](' . OBSERVIUM_DOCS_URL . '/faq/#snmpv3-strong-authentication-or-encryption){target=_blank}.',
'<span style="min-width: 150px;">Please read <a href="' . OBSERVIUM_DOCS_URL . '/faq/#snmpv3-strong-authentication-or-encryption" target="_blank">FAQ</a>.</span>', TRUE ];
// XSS
$array[] = [ 'inside of brackets [javascript:alert(1)], inside of braces {javascript:alert(1)}, inside of parentheses (javascript:alert(1)), [click me](javascript:alert(1))',
'<span style="min-width: 150px;">inside of brackets [javascript:alert(1)], inside of braces {javascript:alert(1)}, inside of parentheses (javascript:alert(1)), <a href="javascript:void(0)">click me</a></span>' ];
// Multiline
$text = <<<TEXT
Welcome to the demo:

View File

@ -5,8 +5,13 @@ $config['install_dir'] = $base_dir;
include(__DIR__ . '/../includes/defaults.inc.php');
//include(dirname(__FILE__) . '/../config.php');
include(__DIR__ . "/../includes/polyfill.inc.php");
include(__DIR__ . "/../includes/autoloader.inc.php");
include(__DIR__ . "/../includes/debugging.inc.php");
require_once(__DIR__ ."/../includes/constants.inc.php");
include(__DIR__ . '/../includes/common.inc.php');
include(__DIR__ . '/../includes/definitions.inc.php');
//include(__DIR__ . '/data/test_definitions.inc.php'); // Fake definitions for testing
include(__DIR__ . '/../includes/functions.inc.php');
class IncludesAlertsTest extends \PHPUnit\Framework\TestCase
@ -292,6 +297,9 @@ class IncludesAlertsTest extends \PHPUnit\Framework\TestCase
$list1 = 'sweet,swoot';
$list2 = array('sweet', 'swoot');
$test4 = 'on';
$list4 = [ 'off', 'offLocked', 'notSet', 0 ];
// in
$array[] = array( TRUE, $test1, 'list', $list1);
@ -314,6 +322,23 @@ class IncludesAlertsTest extends \PHPUnit\Framework\TestCase
$array[] = array(FALSE, $test3, '!in', $list1);
$array[] = array(FALSE, $test3, '!in', $list2);
$array[] = array( TRUE, $test4, 'notin', $list4);
$list1 = '0900,1800';
$list2 = array('0900', '1800');
// between
$array[] = array( TRUE, '1055', 'between', $list1);
$array[] = array( TRUE, '1055', 'between', $list2);
$array[] = array(FALSE, '0855', 'between', $list1);
$array[] = array(FALSE, '1955', 'between', $list2);
// notbetween
$array[] = array(FALSE, '1055', 'notbetween', $list1);
$array[] = array(FALSE, '1055', 'notbetween', $list2);
$array[] = array( TRUE, '0855', '!between', $list1);
$array[] = array( TRUE, '1955', '!between', $list2);
// isnull (second param not used)
$array[] = array(TRUE, NULL, 'isnull', NULL);
$array[] = array(TRUE, NULL, 'null', NULL);

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@
define('OBS_DB_SKIP', FALSE);
//define('OBS_DEBUG', 2);
include(__DIR__ . '/../includes/sql-config.inc.php');
include(__DIR__ . '/../includes/observium.inc.php');
//include(dirname(__FILE__) . '/../includes/defaults.inc.php');
//include(dirname(__FILE__) . '/../config.php');
//include(dirname(__FILE__) . '/../includes/definitions.inc.php');
@ -26,15 +26,6 @@ class IncludesDbTest extends \PHPUnit\Framework\TestCase
$this->assertSame($result, generate_query_values_and($value, $column, $condition));
}
/**
* @dataProvider providerGenerateQueryValues
* @group sql
*/
public function testGenerateQueryValuesCompat($value, $column, $condition, $result)
{
$this->assertSame($result, generate_query_values($value, $column, $condition));
}
/**
* @dataProvider providerGenerateQueryValues
* @group sql
@ -42,14 +33,14 @@ class IncludesDbTest extends \PHPUnit\Framework\TestCase
public function testGenerateQueryValuesNoAnd($value, $column, $condition, $result)
{
$result = preg_replace('/^ AND/', '', $result);
$this->assertSame($result, generate_query_values_ng($value, $column, $condition));
$this->assertSame($result, generate_query_values($value, $column, $condition));
}
public function providerGenerateQueryValues()
{
return array(
// Basic values
array(0, 'test', FALSE, " AND `test` = '0'"),
array(0, 'test', FALSE, " AND `test` = 0"),
array('1,sf,98u8', '`test`', FALSE, " AND `test` = '1,sf,98u8'"),
array(array('1,sf,98u8'), 'I.test', FALSE, " AND `I`.`test` = '1,sf,98u8'"),
array(array('1,sf','98u8', ''), '`I`.`test`', FALSE, " AND IFNULL(`I`.`test`, '') IN ('1,sf','98u8','')"),
@ -57,9 +48,11 @@ class IncludesDbTest extends \PHPUnit\Framework\TestCase
array('"*%F@W)b\'_u<[`R1/#F"', 'test', FALSE, " AND `test` = '\\\"*%F@W)b\'_u<[`R1/#F\\\"'"),
array('*?%_', 'test', FALSE, " AND `test` = '*?%_'"),
// Negative
array(0, 'test', '!=', " AND `test` != 0"),
array(array('1,sf,98u8'), 'I.test', 'NOT', " AND `I`.`test` != '1,sf,98u8'"),
array(array('1,sf,98u8'), 'I.test', '!=', " AND `I`.`test` != '1,sf,98u8'"),
array(array('1,sf,98u8', ''), '`I`.`test`', '!=', " AND IFNULL(`I`.`test`, '') NOT IN ('1,sf,98u8','')"),
// LIKE conditions
array(0, 'test', '%LIKE', " AND (`test` LIKE '%0')"),
array('1,sf,98u8', '`test`', 'LIKE%', " AND (`test` LIKE '1,sf,98u8%')"),
@ -71,13 +64,40 @@ class IncludesDbTest extends \PHPUnit\Framework\TestCase
array('*?%_', 'test', 'LIKE', " AND (`test` LIKE '%_\%\_')"),
// Negative LIKE
array('1,sf,98u8', '`test`', 'NOT LIKE%', " AND (`test` NOT LIKE '1,sf,98u8%')"),
array('1,sf,98u8', '`test`', 'NOT %LIKE', " AND (`test` NOT LIKE '%1,sf,98u8')"),
array('1,sf,98u8', '`test`', 'NOT %LIKE%', " AND (`test` NOT LIKE '%1,sf,98u8%')"),
array(array('1,sf,98u8', ''), '`I`.`test`', 'NOT LIKE', " AND (`I`.`test` NOT LIKE '1,sf,98u8' AND COALESCE(`I`.`test`, '') NOT LIKE '')"),
// REGEXP
[ '^[A-Z]E?PON0/13$', 'test', 'REGEXP', " AND (`test` REGEXP '^[A-Z]E?PON0/13$')" ],
[ '^[A-Z]E?PON0/13$', 'test', 'NOT REGEXP', " AND (`test` NOT REGEXP '^[A-Z]E?PON0/13$')" ],
// Numeric conditions
[ '13', 'test', '>', " AND `test` > 13" ],
[ '13', 'test', '>=', " AND `test` >= 13" ],
[ [ 9, '13'], 'test', '>', " AND `test` > 13" ],
[ [ 9, '13'], 'test', '>=', " AND `test` >= 13" ],
[ 'DATE_SUB(NOW(), INTERVAL 33 HOUR)', 'test', '>', " AND `test` > DATE_SUB(NOW(), INTERVAL 33 HOUR)" ],
[ 'DATE_SUB(NOW(), INTERVAL 33 HOUR)', 'test', '>=', " AND `test` >= DATE_SUB(NOW(), INTERVAL 33 HOUR)" ],
// incorrect numbers
[ '', 'test', '>', " AND 0" ],
[ '13', 'test', '<', " AND `test` < 13" ],
[ '13', 'test', '<=', " AND `test` <= 13" ],
[ [ 9, '13'], 'test', '<', " AND `test` < 9" ],
[ [ 9, '13'], 'test', '<=', " AND `test` <= 9" ],
[ 'DATE_SUB(NOW(), INTERVAL 33 HOUR)', 'test', '<', " AND `test` < DATE_SUB(NOW(), INTERVAL 33 HOUR)" ],
[ 'DATE_SUB(NOW(), INTERVAL 33 HOUR)', 'test', '<=', " AND `test` <= DATE_SUB(NOW(), INTERVAL 33 HOUR)" ],
// incorrect numbers
[ '', 'test', '<', " AND 0" ],
// Duplicates
array(array('1','sf','1','1','98u8',''), '`I`.`test`', FALSE, " AND IFNULL(`I`.`test`, '') IN ('1','sf','98u8','')"),
array(array('1','sf','1','1','98u8',''), '`I`.`test`', FALSE, " AND IFNULL(`I`.`test`, '') IN (1,'sf','98u8','')"),
array(array('1','sf','98u8','1','sf',''), 'I.test', '%LIKE%', " AND (`I`.`test` LIKE '%1%' OR `I`.`test` LIKE '%sf%' OR `I`.`test` LIKE '%98u8%' OR COALESCE(`I`.`test`, '') LIKE '')"),
// Wrong conditions
array('"*%F@W)b\'_u<[`R1/#F"', 'test', 'wtf', " AND `test` = '\\\"*%F@W)b\'_u<[`R1/#F\\\"'"),
array('ssdf', '`test`', TRUE, " AND (`test` LIKE 'ssdf')"),
// Empty values
array(NULL, '`test`', FALSE, " AND IFNULL(`test`, '') = ''"),
array('', '`test`', FALSE, " AND IFNULL(`test`, '') = ''"),

View File

@ -7,336 +7,411 @@ $config['install_dir'] = $base_dir;
include(__DIR__ . '/../includes/defaults.inc.php');
//include(dirname(__FILE__) . '/../config.php'); // Do not include user editable config here
include(__DIR__ . "/../includes/polyfill.inc.php");
include(__DIR__ . "/../includes/autoloader.inc.php");
include(__DIR__ . "/../includes/debugging.inc.php");
require_once(__DIR__ ."/../includes/constants.inc.php");
include(__DIR__ . '/../includes/common.inc.php');
include(__DIR__ . '/../includes/definitions.inc.php');
//include(dirname(__FILE__) . '/data/test_definitions.inc.php'); // Fake definitions for testing
include(__DIR__ . '/../includes/functions.inc.php');
class IncludesDefinitionsTest extends \PHPUnit\Framework\TestCase
{
/**
* @dataProvider providerOsRegex
* @group regex
*/
public function testOsRegex($type, $name, $param, $pattern)
{
$string = 'akjs//?dnasjdn28ye2384y2(&*&(*& '; // Just fake test string
preg_match($pattern, $string);
$preg_error = array_flip(get_defined_constants(true)['pcre'])[preg_last_error()];
class IncludesDefinitionsTest extends \PHPUnit\Framework\TestCase {
// Additional error display
// if ($preg_error != 'PREG_NO_ERROR')
// {
// echo("\n$type -> $name -> $param -> $pattern\n");
// }
protected $backupGlobals = FALSE;
$this->assertSame('PREG_NO_ERROR', $preg_error);
}
public function providerOsRegex()
{
global $config;
$array = [];
foreach ([ 'os_group', 'os', 'mibs'] as $type)
{
foreach ($config[$type] as $name => $entry)
{
foreach ($entry as $param => $def)
{
if (in_array($param, [ 'sysDescr', 'sysDescr_regex', 'port_label', 'syslog_msg', 'syslog_program', 'comments' ]))
{
// simple definitions with regex patterns
foreach ($def as $pattern)
{
$array[] = [$type, $name, $param, $pattern];
}
}
elseif ($param === 'discovery')
{
// discovery definition, additional array level
foreach ($def as $disovery)
{
foreach ($disovery as $discovery_param => $patterns)
{
if (in_array($discovery_param, [ 'sysObjectID', 'os', 'os_group', 'type', 'vendor' ])) { continue; } // All except sysObjectID is regexp
foreach ((array)$patterns as $pattern) {
$array[] = [ $type, $name, $param . '->' . $discovery_param, $pattern ];
}
}
}
}
}
}
}
return $array;
}
/**
* @dataProvider providerDefinitionPatterns
* @group constants
*/
public function testDefinitionPatterns($pattern, $string, $result, $match = NULL) {
$test = preg_match($pattern, $string, $matches);
//var_dump($matches);
$this->assertSame($result, (bool)$test);
if ($test && !is_null($match)) {
// Validate $match
$this->assertSame($match, $matches[1]);
}
}
public function providerDefinitionPatterns() {
$array = array();
$pattern = OBS_PATTERN_IPV4_FULL;
// IPv4 valid
$array[] = array($pattern, '1.2.3.4', TRUE, '1.2.3.4');
$array[] = array($pattern, '255.255.255.255', TRUE, '255.255.255.255');
// IPv4 invalid
$array[] = array($pattern, '1.2.3', FALSE);
$array[] = array($pattern, '1.2.3.', FALSE);
$array[] = array($pattern, '.1.2.3', FALSE);
$array[] = array($pattern, '1.2.3.4.5.6.7.8', FALSE);
$array[] = array($pattern, '999.999.999.999', FALSE);
$array[] = array($pattern, '299.299.299.299', FALSE);
$array[] = array($pattern, '001.002.003.004', FALSE);
// IPv4 in strings
$array[] = array($pattern, '"1.2.3.4"', TRUE, '1.2.3.4');
$array[] = array($pattern, '(1.2.3.4)', TRUE, '1.2.3.4');
$array[] = array($pattern, '(1.2.3.4, tprrrr)', TRUE, '1.2.3.4');
$array[] = array($pattern, 'PING is1.nic.local (192.168.10.110): 56 data bytes', TRUE, '192.168.10.110');
$array[] = array($pattern, '64 bytes from 192.168.10.110: icmp_seq=0 ttl=122 time=10.643 ms', TRUE, '192.168.10.110');
$array[] = array($pattern, 'Invalid user test from 213.149.105.28', TRUE, '213.149.105.28');
$array[] = array($pattern, 'Invalid user test from 213.149.105.28 hs', TRUE, '213.149.105.28');
$array[] = array($pattern, 'Invalid user test from 213.149.105.28. Next.', TRUE, '213.149.105.28');
$array[] = array($pattern, 'Invalid user test from 213.149.105.28sss', FALSE);
$pattern = OBS_PATTERN_IPV4_NET_FULL;
// IPv4 network valid
$array[] = array($pattern, '1.2.3.4/0', TRUE, '1.2.3.4/0');
$array[] = array($pattern, '1.2.3.4/29', TRUE, '1.2.3.4/29');
$array[] = array($pattern, '1.2.3.4/32', TRUE, '1.2.3.4/32');
// IPv4 network with netmask valid
$array[] = array($pattern, '1.2.3.4/0.0.0.0', TRUE, '1.2.3.4/0.0.0.0');
$array[] = array($pattern, '1.2.3.4/255.255.255.248', TRUE, '1.2.3.4/255.255.255.248');
$array[] = array($pattern, '1.2.3.4/255.255.255.255', TRUE, '1.2.3.4/255.255.255.255');
// IPv4 network with Cisco inverse netmask valid
$array[] = array($pattern, '1.2.3.4/0.0.63.255', TRUE, '1.2.3.4/0.0.63.255');
$array[] = array($pattern, '1.2.3.4/0.0.0.1', TRUE, '1.2.3.4/0.0.0.1');
$array[] = array($pattern, '1.2.3.4/127.255.255.255', TRUE, '1.2.3.4/127.255.255.255');
// IPv4 network invalid
$array[] = array($pattern, '1.2.3.4/-1', FALSE);
$array[] = array($pattern, '1.2.3.4/33', FALSE);
$array[] = array($pattern, '1.2.3.4/123', FALSE);
// IPv4 network with invalid netmask
$array[] = array($pattern, '1.2.3.4/1.2.3.4', FALSE);
$array[] = array($pattern, '1.2.3.4/128.128.128.300', FALSE);
// IPv4 address (without prefix) also invalid
$array[] = array($pattern, '1.2.3.4', FALSE);
$pattern = OBS_PATTERN_IPV6_FULL;
// IPv6 valid
$array[] = array($pattern, '1762:0:0:0:0:B03:1:AF18', TRUE, '1762:0:0:0:0:B03:1:AF18');
$array[] = array($pattern, 'FE80:FFFF:0:FFFF:129:144:52:38', TRUE, 'FE80:FFFF:0:FFFF:129:144:52:38');
$array[] = array($pattern, 'FF01:0:0:0:CA:0:0:2', TRUE, 'FF01:0:0:0:CA:0:0:2');
$array[] = array($pattern, '0:0:0:0:0:0:0:1', TRUE, '0:0:0:0:0:0:0:1');
$array[] = array($pattern, '0:0:0:0:0:0:0:0', TRUE, '0:0:0:0:0:0:0:0');
$array[] = array($pattern, '1762::B03:1:AF18', TRUE, '1762::B03:1:AF18');
$array[] = array($pattern, 'FF01:7:CA:0::', TRUE, 'FF01:7:CA:0::');
$array[] = array($pattern, '::FF01:7:CA:0', TRUE, '::FF01:7:CA:0');
$array[] = array($pattern, '::1', TRUE, '::1');
$array[] = array($pattern, '1::', TRUE, '1::');
$array[] = array($pattern, '::', TRUE, '::');
$array[] = array($pattern, '::1:2:3:4:5:6:7', TRUE, '::1:2:3:4:5:6:7');
$array[] = array($pattern, '1:2:3:4:5:6:7::', TRUE, '1:2:3:4:5:6:7::');
$array[] = array($pattern, '0:0:0:0:0:0:127.32.67.15', TRUE, '0:0:0:0:0:0:127.32.67.15');
$array[] = array($pattern, '0:0:0:0:0:FFFF:127.32.67.15', TRUE, '0:0:0:0:0:FFFF:127.32.67.15');
$array[] = array($pattern, '::127.32.67.15', TRUE, '::127.32.67.15');
$array[] = array($pattern, '::FFFF:127.32.67.15', TRUE, '::FFFF:127.32.67.15');
$array[] = array($pattern, 'FFFF::127.32.67.15', TRUE, 'FFFF::127.32.67.15');
$array[] = array($pattern, '::1:2:3:4:5:127.32.67.15', TRUE, '::1:2:3:4:5:127.32.67.15');
// IPv6 invalid
$array[] = array($pattern, '1762:0:0:0:0:B03G:1:AF18', FALSE);
$array[] = array($pattern, ':127.32.67.15', FALSE);
$array[] = array($pattern, ':1234:127.32.67.15', FALSE);
$array[] = array($pattern, ':1234:1234:1234', FALSE);
$array[] = array($pattern, '1234:1234:1234:', FALSE);
$array[] = array($pattern, '1234::234::234::2342', FALSE);
$array[] = array($pattern, '1234:1234:1234:1234:1234:1234:1234:1234:1234:1234:1234', FALSE);
$array[] = array($pattern, '1234:1234:1234:1234::1234:1234:1234:1234:1234:1234:1234', FALSE);
$array[] = array($pattern, '1234:1234:1234:1234::1234:1234:1234:1234:1234::1234:1234', FALSE);
// IPv6 in strings
$array[] = array($pattern, '"FF01:7:CA:0::"', TRUE, 'FF01:7:CA:0::');
$array[] = array($pattern, '(FF01:7:CA:0::)', TRUE, 'FF01:7:CA:0::');
$array[] = array($pattern, '(FF01:7:CA:0::, hoho)', TRUE, 'FF01:7:CA:0::');
$array[] = array($pattern, 'PING6(56=40+8+8 bytes) 2a02:408:8093:fff2::4 --> 2a02:408:7722:41::150', TRUE, '2a02:408:8093:fff2::4');
$array[] = array($pattern, '16 bytes from 2a02:408:7722:41::150, icmp_seq=0 hlim=62 time=1.717 ms', TRUE, '2a02:408:7722:41::150');
$array[] = array($pattern, 'RP/0/RSP0/CPU0:May 31 16:23:46.207 : bgp[1046]: %ROUTING-BGP-5-ADJCHANGE : neighbor 2a02:2090:e400:4400::9:2 Up (VRF: default) (AS: 43489)', TRUE, '2a02:2090:e400:4400::9:2');
$array[] = array($pattern, 'RP/0/RSP0/CPU0:May 31 16:23:46.207 : bgp[1046]: %ROUTING-BGP-5-ADJCHANGE : neighbor 2a02:2090:e400:4400::9:2', TRUE, '2a02:2090:e400:4400::9:2');
$array[] = array($pattern, 'RP/0/RSP0/CPU0:May 31 16:23:46.207 : bgp[1046]: %ROUTING-BGP-5-ADJCHANGE : neighbor 2a02:2090:e400:4400::9:2Up', FALSE);
$pattern = OBS_PATTERN_IPV6_NET_FULL;
// IPv6 network valid
$array[] = array($pattern, '1762:0:0:0:0:B03:1:AF18/0', TRUE, '1762:0:0:0:0:B03:1:AF18/0');
$array[] = array($pattern, '1762:0:0:0:0:B03:1:AF18/29', TRUE, '1762:0:0:0:0:B03:1:AF18/29');
$array[] = array($pattern, '1762:0:0:0:0:B03:1:AF18/99', TRUE, '1762:0:0:0:0:B03:1:AF18/99');
$array[] = array($pattern, '1762:0:0:0:0:B03:1:AF18/119', TRUE, '1762:0:0:0:0:B03:1:AF18/119');
$array[] = array($pattern, '1762:0:0:0:0:B03:1:AF18/128', TRUE, '1762:0:0:0:0:B03:1:AF18/128');
// IPv6 network invalid
$array[] = array($pattern, '1762:0:0:0:0:B03:1:AF18/-1', FALSE);
$array[] = array($pattern, '1762:0:0:0:0:B03:1:AF18/129', FALSE);
// IPv6 address (without prefix) also invalid
$array[] = array($pattern, '1762:0:0:0:0:B03:1:AF18', FALSE);
$pattern = OBS_PATTERN_IP_FULL;
// IPv4 OR IPv6 valid (combination of patterns)
$array[] = array($pattern, '1.2.3.4', TRUE, '1.2.3.4');
$array[] = array($pattern, '1762:0:0:0:0:B03:1:AF18', TRUE, '1762:0:0:0:0:B03:1:AF18');
$pattern = OBS_PATTERN_MAC_FULL;
// MAC valid
$array[] = array($pattern, '0026.22eb.3bef', TRUE, '0026.22eb.3bef'); // Cisco
$array[] = array($pattern, '00-02-2D-11-55-4D', TRUE, '00-02-2D-11-55-4D'); // Windows
$array[] = array($pattern, '00 0D 93 13 51 1A', TRUE, '00 0D 93 13 51 1A'); // Old Unix
$array[] = array($pattern, '0x000E7F0D81D6', TRUE, '0x000E7F0D81D6'); // HP-UX
$array[] = array($pattern, '0004E25AA118', TRUE, '0004E25AA118'); // DOS, RAW
$array[] = array($pattern, '00:08:C7:1B:8C:02', TRUE, '00:08:C7:1B:8C:02'); // Unix/Linux
$array[] = array($pattern, '8:0:86:b6:82:9f', TRUE, '8:0:86:b6:82:9f'); // SNMP, Solaris
// MAC invalid
$array[] = array($pattern, 'F1:0:0:0:CA:0:0:2', FALSE); // IPv6
$array[] = array($pattern, '0026.22eb.3be', FALSE);
$array[] = array($pattern, '00-2-2D-11-55-4D', FALSE);
$array[] = array($pattern, '00 D 93 13 51 1A', FALSE);
$array[] = array($pattern, '0x00E7F0D81D6', FALSE);
$array[] = array($pattern, '004E25AA118', FALSE);
$array[] = array($pattern, '00:0G:C7:1B:8C:02', FALSE);
$array[] = array($pattern, '8::86:b6:82:9f', FALSE);
$array[] = array($pattern, '00 0D-93 13 51 1A', FALSE);
$array[] = array($pattern, '00 0D 93:13 51 1A', FALSE);
$array[] = array($pattern, '00 0D.93 13.51 1A', FALSE);
$array[] = array($pattern, '0x901b', FALSE);
$array[] = array($pattern, '08-00-27-00-5049', FALSE);
$array[] = array($pattern, '08:00:27:00:5049', FALSE);
$array[] = array($pattern, '08-00-27-00-50--49', FALSE);
$array[] = array($pattern, '08:00:27:00:50::49', FALSE);
$array[] = array($pattern, '08-00-27-00-50-49-', FALSE);
$array[] = array($pattern, '08:00:27:00:50:49:', FALSE);
$array[] = array($pattern, '-08-00-27-00-50-49', FALSE);
$array[] = array($pattern, ':08:00:27:00:50:49', FALSE);
$array[] = array($pattern, ':080027005049', FALSE);
// MAC in strings
$array[] = array($pattern, '"0026.22eb.3bef"', TRUE, '0026.22eb.3bef');
$array[] = array($pattern, '(0026.22eb.3bef)', TRUE, '0026.22eb.3bef');
$array[] = array($pattern, '(0026.22eb.3bef, qu-qu)', TRUE, '0026.22eb.3bef');
$array[] = array($pattern, 'wevent.ubnt_custom_event(): EVENT_STA_IP ath3: 9c:4f:da:73:5c:cc / 10.10.35.16', TRUE, '9c:4f:da:73:5c:cc');
$array[] = array($pattern, 'ath0: STA 44:d9:e7:f7:18:f2 DRIVER: Sead AUTH addr=9c:4f:da:73:5c:cc status_code=0', TRUE, '44:d9:e7:f7:18:f2');
$array[] = array($pattern, 'ath0: STA 44:d9:e7:f7:18:f2. DRIVER: Sead AUTH addr=9c:4f:da:73:5c:cc status_code=0', TRUE, '44:d9:e7:f7:18:f2');
$array[] = array($pattern, 'wevent.ubnt_custom_event(): EVENT_STA_IP ath3: 9c:4f:da:73:5c:cccc', FALSE);
$array[] = array($pattern, 'Host 0016.3e2e.2b98 in vlan 400 is flapping between port Gi1/0/25 and port Te1/0/1', TRUE, '0016.3e2e.2b98');
$pattern = OBS_PATTERN_FQDN_FULL;
// Domain name valid
$array[] = array($pattern, 'observium.org', TRUE, 'observium.org');
$array[] = array($pattern, 'my.host-name.test', TRUE, 'my.host-name.test');
$array[] = array($pattern, 'qq.ff.ee.my.host-name.test', TRUE, 'qq.ff.ee.my.host-name.test');
$array[] = array($pattern, 'localhost', TRUE, 'localhost');
// 1234567890123456789012345678901234567890123456789012345678901234
$array[] = array($pattern, 'my-yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy-63char.name', TRUE, 'my-yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy-63char.name');
$array[] = array($pattern, 'external.asd1230-123.asd_internal.asd.gm-_ail.com', TRUE, 'external.asd1230-123.asd_internal.asd.gm-_ail.com');
// Domain name IDN
$array[] = array($pattern, 'xn--b1agh1afp.xn--p1ai', TRUE, 'xn--b1agh1afp.xn--p1ai'); // привет.рф
$array[] = array($pattern, 'привет.рф', TRUE, 'привет.рф'); // привет.рф
// Domain name invalid
$array[] = array($pattern, '::127.32.67.15', FALSE);
$array[] = array($pattern, '1.2.3', FALSE);
$array[] = array($pattern, '1.2.3.4', FALSE);
$array[] = array($pattern, '.1.2.3', FALSE);
$array[] = array($pattern, '1.2.3.4.5.6.7.8', FALSE);
$array[] = array($pattern, '999.999.999.999', FALSE);
$array[] = array($pattern, '299.299.299.299', FALSE);
$array[] = array($pattern, '001.002.003.004', FALSE);
$array[] = array($pattern, 'test', FALSE);
$array[] = array($pattern, 'example..com', FALSE);
$array[] = array($pattern, 'http://example.com', FALSE);
$array[] = array($pattern, 'subdomain.-example.com', FALSE);
$array[] = array($pattern, 'example.com/parameter', FALSE);
$array[] = array($pattern, 'example.com?anything', FALSE);
$array[] = array($pattern, 'GigabitEthernet0/1.ServiceInstance.206', FALSE);
// 1234567890123456789012345678901234567890123456789012345678901234
$array[] = array($pattern, 'my-yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy-64char.name', FALSE);
// Domain name in strings
$array[] = array($pattern, '"my.host-name.test"', TRUE, 'my.host-name.test');
$array[] = array($pattern, '(my.host-name.test)', TRUE, 'my.host-name.test');
$array[] = array($pattern, '(my.host-name.test, help)', TRUE, 'my.host-name.test');
$array[] = array($pattern, 'Invalid user test from my.host-name.test', TRUE, 'my.host-name.test');
$array[] = array($pattern, 'Invalid user test from my.host-name.test hs', TRUE, 'my.host-name.test');
$array[] = array($pattern, 'Invalid user test from my.host-name.test.', TRUE, 'my.host-name.test');
$pattern = OBS_PATTERN_EMAIL_FULL;
// Email valid
$array[] = array($pattern, 'president@whitehouse.gov', TRUE, 'president@whitehouse.gov');
$array[] = array($pattern, 'pharaoh@egyptian.museum', TRUE, 'pharaoh@egyptian.museum');
$array[] = array($pattern, 'john.doe+test@ee.my.host-name.test', TRUE, 'john.doe+test@ee.my.host-name.test');
$array[] = array($pattern, 'Mike.O\'Dell@ireland.com', TRUE, 'Mike.O\'Dell@ireland.com');
$array[] = array($pattern, '"Mike\\\\ O\'Dell"@ireland.com', TRUE, '"Mike\\\\ O\'Dell"@ireland.com');
// 1234567890123456789012345678901234567890123456789012345678901234
$array[] = array($pattern, 'user-----------------------------------------------------63char@my-yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy-63char.name', TRUE,
'user-----------------------------------------------------63char@my-yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy-63char.name');
//$array[] = array($pattern, 'external.asd1230-123.asd_internal.asd.gm-_ail.com', TRUE, 'external.asd1230-123.asd_internal.asd.gm-_ail.com');
// Email IDN
$array[] = array($pattern, 'mike@xn--b1agh1afp.xn--p1ai', TRUE, 'mike@xn--b1agh1afp.xn--p1ai'); // mike@привет.рф
$array[] = array($pattern, 'майк@привет.рф', TRUE, 'майк@привет.рф'); // майк@привет.рф
// Email invalid
$array[] = array($pattern, '1024x768@60Hz', FALSE);
$array[] = array($pattern, 'not.a.valid.email', FALSE);
$array[] = array($pattern, 'john@example...com', FALSE);
$array[] = array($pattern, 'joe@ha!ha!.com', FALSE);
// 1234567890123456789012345678901234567890123456789012345678901234
$array[] = array($pattern, 'joe@a_domain_name_with_more_than_sixty-four_characters_is_invalid_6465.com', FALSE);
$array[] = array($pattern, 'a_local_part_with_more_than_sixty-four_characters_is_invalid_6465@mail.com', FALSE);
//$array[] = array($pattern, 'the_total_length_of_an_email_address_is_limited@two-hundred-fifty-four-characters.because-the-SMTP-protocol-for-sending-email.does-not-support-more-than-that.really-hard-to-come-up-with-a-bogus-address-as-long-as-this.still-not-long-enough.too-long-now.com', FALSE);
// Email in strings
$array[] = array($pattern, '"test@domain.name"', TRUE, 'test@domain.name');
$array[] = array($pattern, '(test@domain.name)', TRUE, 'test@domain.name');
$array[] = array($pattern, '(test@domain.name, help)', TRUE, 'test@domain.name');
$array[] = array($pattern, 'The email address president@whitehouse.gov is valid.', TRUE, 'president@whitehouse.gov');
$array[] = array($pattern, 'fabio@disapproved.solutions has a long TLD', TRUE, 'fabio@disapproved.solutions');
$pattern = OBS_PATTERN_EMAIL_LONG_FULL;
// Email valid
$array[] = array($pattern, '<test@domain.name>', TRUE, '<test@domain.name>');
$array[] = array($pattern, 'Pharaoh <pharaoh@egyptian.museum>', TRUE, 'Pharaoh <pharaoh@egyptian.museum>');
$array[] = array($pattern, 'in Egypt "Pharaoh" <pharaoh@egyptian.museum>', TRUE, '"Pharaoh" <pharaoh@egyptian.museum>');
$array[] = array($pattern, 'Pharaoh of Egypt <pharaoh@egyptian.museum>', TRUE, 'Pharaoh of Egypt <pharaoh@egyptian.museum>');
$array[] = array($pattern, '"Mike O\'Dell" <Mike.O\'Dell@ireland.com>', TRUE, '"Mike O\'Dell" <Mike.O\'Dell@ireland.com>');
// Email invalid
$array[] = array($pattern, '<domain.name>', FALSE);
$array[] = array($pattern, 'Pharaoh <pharaoh@>', FALSE);
$array[] = array($pattern, 'Test Title test@example.com', FALSE);
/*
$pattern = OBS_PATTERN_URL_FULL;
// URL IDN
$array[] = array($pattern, 'https://www.get.no/v3/bredb%C3%A5nd/tr%C3%A5dl%C3%B8st-modem', TRUE,
'https://www.get.no/v3/bredb%C3%A5nd/tr%C3%A5dl%C3%B8st-modem');
// URL in string
$array[] = array($pattern, '<a href="https://www.get.no/v3/bredb%C3%A5nd/tr%C3%A5dl%C3%B8st-modem" rel="nofollow">https://www.get.no/v3/bredbånd/trådløst-modem</a>', TRUE,
'https://www.get.no/v3/bredb%C3%A5nd/tr%C3%A5dl%C3%B8st-modem');
/**
* @dataProvider providerOsRegex
* @group regex
*/
public function testOsRegex($type, $name, $param, $pattern) {
$string = 'akjs//?dnasjdn28ye2384y2(&*&(*& '; // Just fake test string
preg_match($pattern, $string);
$preg_error = array_flip(get_defined_constants(true)['pcre'])[preg_last_error()];
$pattern = OBS_PATTERN_NOPRINT;
// Not printable chars
$array[] = array($pattern, "ABC \n", TRUE);
$array[] = array($pattern, "ABC \r", TRUE);
$array[] = array($pattern, "ABC \t", TRUE);
// All printable
$array[] = array($pattern, "ABC ËЙЦ 10 œ∑√∫Ω≈∆µ \"',.:`~!@#$%^&*()_+-=<>?/[]{}|\\", FALSE);
// Additional error display
// if ($preg_error != 'PREG_NO_ERROR')
// {
// echo("\n$type -> $name -> $param -> $pattern\n");
// }
return $array;
}
$this->assertSame('PREG_NO_ERROR', $preg_error);
}
public function providerOsRegex() {
global $config;
$array = [];
foreach ([ 'os_group', 'os', 'mibs'] as $type) {
foreach ($config[$type] as $name => $entry) {
foreach ($entry as $param => $def) {
if (in_array($param, [ 'sysDescr', 'sysDescr_regex', 'port_label', 'syslog_msg', 'syslog_program', 'comments' ])) {
// simple definitions with regex patterns
foreach ($def as $pattern) {
$array[] = [ $type, $name, $param, $pattern ];
}
} elseif ($param === 'discovery') {
// discovery definition, additional array level
foreach ($def as $disovery) {
foreach ($disovery as $discovery_param => $patterns) {
if (in_array($discovery_param, [ 'sysObjectID', 'os', 'os_group', 'type', 'vendor' ])) { continue; } // All except sysObjectID is regexp
foreach ((array)$patterns as $pattern) {
$array[] = [ $type, $name, $param . '->' . $discovery_param, $pattern ];
}
}
}
}
}
}
}
return $array;
}
/**
* @dataProvider providerDefinitionPatterns
* @group constants
*/
public function testDefinitionPatterns($pattern, $string, $result, $match = NULL) {
$test = preg_match($pattern, $string, $matches);
//var_dump($matches);
$this->assertSame($result, (bool)$test);
if ($test) {
if (is_array($match)) {
$this->assertSame($match, $matches);
} elseif (!is_null($match)) {
// Validate $match
$this->assertSame($match, $matches[1]);
}
}
}
public function providerDefinitionPatterns() {
$array = [];
$pattern = OBS_PATTERN_IPV4_FULL;
// IPv4 valid
$array[] = array($pattern, '1.2.3.4', TRUE, '1.2.3.4');
$array[] = array($pattern, '255.255.255.255', TRUE, '255.255.255.255');
// IPv4 invalid
$array[] = array($pattern, '1.2.3', FALSE);
$array[] = array($pattern, '1.2.3.', FALSE);
$array[] = array($pattern, '.1.2.3', FALSE);
$array[] = array($pattern, '1.2.3.4.5.6.7.8', FALSE);
$array[] = array($pattern, '999.999.999.999', FALSE);
$array[] = array($pattern, '299.299.299.299', FALSE);
$array[] = array($pattern, '001.002.003.004', FALSE);
// IPv4 in strings
$array[] = array($pattern, '"1.2.3.4"', TRUE, '1.2.3.4');
$array[] = array($pattern, '(1.2.3.4)', TRUE, '1.2.3.4');
$array[] = array($pattern, '(1.2.3.4, tprrrr)', TRUE, '1.2.3.4');
$array[] = array($pattern, 'PING is1.nic.local (192.168.10.110): 56 data bytes', TRUE, '192.168.10.110');
$array[] = array($pattern, '64 bytes from 192.168.10.110: icmp_seq=0 ttl=122 time=10.643 ms', TRUE, '192.168.10.110');
$array[] = array($pattern, 'Invalid user test from 213.149.105.28', TRUE, '213.149.105.28');
$array[] = array($pattern, 'Invalid user test from 213.149.105.28 hs', TRUE, '213.149.105.28');
$array[] = array($pattern, 'Invalid user test from 213.149.105.28. Next.', TRUE, '213.149.105.28');
$array[] = array($pattern, 'Invalid user test from 213.149.105.28sss', FALSE);
$pattern = OBS_PATTERN_IPV4_NET_FULL;
// IPv4 network valid
$array[] = array($pattern, '1.2.3.4/0', TRUE, '1.2.3.4/0');
$array[] = array($pattern, '1.2.3.4/29', TRUE, '1.2.3.4/29');
$array[] = array($pattern, '1.2.3.4/32', TRUE, '1.2.3.4/32');
// IPv4 network with netmask valid
$array[] = array($pattern, '1.2.3.4/0.0.0.0', TRUE, '1.2.3.4/0.0.0.0');
$array[] = array($pattern, '1.2.3.4/255.255.255.248', TRUE, '1.2.3.4/255.255.255.248');
$array[] = array($pattern, '1.2.3.4/255.255.255.255', TRUE, '1.2.3.4/255.255.255.255');
// IPv4 network with Cisco inverse netmask valid
$array[] = array($pattern, '1.2.3.4/0.0.63.255', TRUE, '1.2.3.4/0.0.63.255');
$array[] = array($pattern, '1.2.3.4/0.0.0.1', TRUE, '1.2.3.4/0.0.0.1');
$array[] = array($pattern, '1.2.3.4/127.255.255.255', TRUE, '1.2.3.4/127.255.255.255');
// IPv4 network invalid
$array[] = array($pattern, '1.2.3.4/-1', FALSE);
$array[] = array($pattern, '1.2.3.4/33', FALSE);
$array[] = array($pattern, '1.2.3.4/123', FALSE);
// IPv4 network with invalid netmask
$array[] = array($pattern, '1.2.3.4/1.2.3.4', FALSE);
$array[] = array($pattern, '1.2.3.4/128.128.128.300', FALSE);
// IPv4 address (without prefix) also invalid
$array[] = array($pattern, '1.2.3.4', FALSE);
$pattern = OBS_PATTERN_IPV6_FULL;
// IPv6 valid
$array[] = array($pattern, '1762:0:0:0:0:B03:1:AF18', TRUE, '1762:0:0:0:0:B03:1:AF18');
$array[] = array($pattern, 'FE80:FFFF:0:FFFF:129:144:52:38', TRUE, 'FE80:FFFF:0:FFFF:129:144:52:38');
$array[] = array($pattern, 'FF01:0:0:0:CA:0:0:2', TRUE, 'FF01:0:0:0:CA:0:0:2');
$array[] = array($pattern, '0:0:0:0:0:0:0:1', TRUE, '0:0:0:0:0:0:0:1');
$array[] = array($pattern, '0:0:0:0:0:0:0:0', TRUE, '0:0:0:0:0:0:0:0');
$array[] = array($pattern, '1762::B03:1:AF18', TRUE, '1762::B03:1:AF18');
$array[] = array($pattern, 'FF01:7:CA:0::', TRUE, 'FF01:7:CA:0::');
$array[] = array($pattern, '::FF01:7:CA:0', TRUE, '::FF01:7:CA:0');
$array[] = array($pattern, '::1', TRUE, '::1');
$array[] = array($pattern, '1::', TRUE, '1::');
$array[] = array($pattern, '::', TRUE, '::');
$array[] = array($pattern, '::1:2:3:4:5:6:7', TRUE, '::1:2:3:4:5:6:7');
$array[] = array($pattern, '1:2:3:4:5:6:7::', TRUE, '1:2:3:4:5:6:7::');
$array[] = array($pattern, '0:0:0:0:0:0:127.32.67.15', TRUE, '0:0:0:0:0:0:127.32.67.15');
$array[] = array($pattern, '0:0:0:0:0:FFFF:127.32.67.15', TRUE, '0:0:0:0:0:FFFF:127.32.67.15');
$array[] = array($pattern, '::127.32.67.15', TRUE, '::127.32.67.15');
$array[] = array($pattern, '::FFFF:127.32.67.15', TRUE, '::FFFF:127.32.67.15');
$array[] = array($pattern, 'FFFF::127.32.67.15', TRUE, 'FFFF::127.32.67.15');
$array[] = array($pattern, '::1:2:3:4:5:127.32.67.15', TRUE, '::1:2:3:4:5:127.32.67.15');
// IPv6 invalid
$array[] = array($pattern, '1762:0:0:0:0:B03G:1:AF18', FALSE);
$array[] = array($pattern, ':127.32.67.15', FALSE);
$array[] = array($pattern, ':1234:127.32.67.15', FALSE);
$array[] = array($pattern, ':1234:1234:1234', FALSE);
$array[] = array($pattern, '1234:1234:1234:', FALSE);
$array[] = array($pattern, '1234::234::234::2342', FALSE);
$array[] = array($pattern, '1234:1234:1234:1234:1234:1234:1234:1234:1234:1234:1234', FALSE);
$array[] = array($pattern, '1234:1234:1234:1234::1234:1234:1234:1234:1234:1234:1234', FALSE);
$array[] = array($pattern, '1234:1234:1234:1234::1234:1234:1234:1234:1234::1234:1234', FALSE);
// IPv6 in strings
$array[] = array($pattern, '"FF01:7:CA:0::"', TRUE, 'FF01:7:CA:0::');
$array[] = array($pattern, '(FF01:7:CA:0::)', TRUE, 'FF01:7:CA:0::');
$array[] = array($pattern, '(FF01:7:CA:0::, hoho)', TRUE, 'FF01:7:CA:0::');
$array[] = array($pattern, 'PING6(56=40+8+8 bytes) 2a02:408:8093:fff2::4 --> 2a02:408:7722:41::150', TRUE, '2a02:408:8093:fff2::4');
$array[] = array($pattern, '16 bytes from 2a02:408:7722:41::150, icmp_seq=0 hlim=62 time=1.717 ms', TRUE, '2a02:408:7722:41::150');
$array[] = array($pattern, 'RP/0/RSP0/CPU0:May 31 16:23:46.207 : bgp[1046]: %ROUTING-BGP-5-ADJCHANGE : neighbor 2a02:2090:e400:4400::9:2 Up (VRF: default) (AS: 43489)', TRUE, '2a02:2090:e400:4400::9:2');
$array[] = array($pattern, 'RP/0/RSP0/CPU0:May 31 16:23:46.207 : bgp[1046]: %ROUTING-BGP-5-ADJCHANGE : neighbor 2a02:2090:e400:4400::9:2', TRUE, '2a02:2090:e400:4400::9:2');
$array[] = array($pattern, 'RP/0/RSP0/CPU0:May 31 16:23:46.207 : bgp[1046]: %ROUTING-BGP-5-ADJCHANGE : neighbor 2a02:2090:e400:4400::9:2Up', FALSE);
$pattern = OBS_PATTERN_IPV6_NET_FULL;
// IPv6 network valid
$array[] = array($pattern, '1762:0:0:0:0:B03:1:AF18/0', TRUE, '1762:0:0:0:0:B03:1:AF18/0');
$array[] = array($pattern, '1762:0:0:0:0:B03:1:AF18/29', TRUE, '1762:0:0:0:0:B03:1:AF18/29');
$array[] = array($pattern, '1762:0:0:0:0:B03:1:AF18/99', TRUE, '1762:0:0:0:0:B03:1:AF18/99');
$array[] = array($pattern, '1762:0:0:0:0:B03:1:AF18/119', TRUE, '1762:0:0:0:0:B03:1:AF18/119');
$array[] = array($pattern, '1762:0:0:0:0:B03:1:AF18/128', TRUE, '1762:0:0:0:0:B03:1:AF18/128');
// IPv6 network invalid
$array[] = array($pattern, '1762:0:0:0:0:B03:1:AF18/-1', FALSE);
$array[] = array($pattern, '1762:0:0:0:0:B03:1:AF18/129', FALSE);
// IPv6 address (without prefix) also invalid
$array[] = array($pattern, '1762:0:0:0:0:B03:1:AF18', FALSE);
$pattern = OBS_PATTERN_IP_FULL;
// IPv4 OR IPv6 valid (combination of patterns)
$array[] = array($pattern, '1.2.3.4', TRUE, '1.2.3.4');
$array[] = array($pattern, '1762:0:0:0:0:B03:1:AF18', TRUE, '1762:0:0:0:0:B03:1:AF18');
$pattern = OBS_PATTERN_MAC_FULL;
// MAC valid
$array[] = array($pattern, '0026.22eb.3bef', TRUE, '0026.22eb.3bef'); // Cisco
$array[] = array($pattern, '00-02-2D-11-55-4D', TRUE, '00-02-2D-11-55-4D'); // Windows
$array[] = array($pattern, '00 0D 93 13 51 1A', TRUE, '00 0D 93 13 51 1A'); // Old Unix
$array[] = array($pattern, '0x000E7F0D81D6', TRUE, '0x000E7F0D81D6'); // HP-UX
$array[] = array($pattern, '0004E25AA118', TRUE, '0004E25AA118'); // DOS, RAW
$array[] = array($pattern, '00:08:C7:1B:8C:02', TRUE, '00:08:C7:1B:8C:02'); // Unix/Linux
$array[] = array($pattern, '8:0:86:b6:82:9f', TRUE, '8:0:86:b6:82:9f'); // SNMP, Solaris
// MAC invalid
$array[] = array($pattern, 'F1:0:0:0:CA:0:0:2', FALSE); // IPv6
$array[] = array($pattern, '0026.22eb.3be', FALSE);
$array[] = array($pattern, '00-2-2D-11-55-4D', FALSE);
$array[] = array($pattern, '00 D 93 13 51 1A', FALSE);
$array[] = array($pattern, '0x00E7F0D81D6', FALSE);
$array[] = array($pattern, '004E25AA118', FALSE);
$array[] = array($pattern, '00:0G:C7:1B:8C:02', FALSE);
$array[] = array($pattern, '8::86:b6:82:9f', FALSE);
$array[] = array($pattern, '00 0D-93 13 51 1A', FALSE);
$array[] = array($pattern, '00 0D 93:13 51 1A', FALSE);
$array[] = array($pattern, '00 0D.93 13.51 1A', FALSE);
$array[] = array($pattern, '0x901b', FALSE);
$array[] = array($pattern, '08-00-27-00-5049', FALSE);
$array[] = array($pattern, '08:00:27:00:5049', FALSE);
$array[] = array($pattern, '08-00-27-00-50--49', FALSE);
$array[] = array($pattern, '08:00:27:00:50::49', FALSE);
$array[] = array($pattern, '08-00-27-00-50-49-', FALSE);
$array[] = array($pattern, '08:00:27:00:50:49:', FALSE);
$array[] = array($pattern, '-08-00-27-00-50-49', FALSE);
$array[] = array($pattern, ':08:00:27:00:50:49', FALSE);
$array[] = array($pattern, ':080027005049', FALSE);
// MAC in strings
$array[] = array($pattern, '"0026.22eb.3bef"', TRUE, '0026.22eb.3bef');
$array[] = array($pattern, '(0026.22eb.3bef)', TRUE, '0026.22eb.3bef');
$array[] = array($pattern, '(0026.22eb.3bef, qu-qu)', TRUE, '0026.22eb.3bef');
$array[] = array($pattern, 'wevent.ubnt_custom_event(): EVENT_STA_IP ath3: 9c:4f:da:73:5c:cc / 10.10.35.16', TRUE, '9c:4f:da:73:5c:cc');
$array[] = array($pattern, 'ath0: STA 44:d9:e7:f7:18:f2 DRIVER: Sead AUTH addr=9c:4f:da:73:5c:cc status_code=0', TRUE, '44:d9:e7:f7:18:f2');
$array[] = array($pattern, 'ath0: STA 44:d9:e7:f7:18:f2. DRIVER: Sead AUTH addr=9c:4f:da:73:5c:cc status_code=0', TRUE, '44:d9:e7:f7:18:f2');
$array[] = array($pattern, 'wevent.ubnt_custom_event(): EVENT_STA_IP ath3: 9c:4f:da:73:5c:cccc', FALSE);
$array[] = array($pattern, 'Host 0016.3e2e.2b98 in vlan 400 is flapping between port Gi1/0/25 and port Te1/0/1', TRUE, '0016.3e2e.2b98');
$pattern = OBS_PATTERN_FQDN_FULL;
// Domain name valid
$array[] = array($pattern, 'observium.org', TRUE, 'observium.org');
$array[] = array($pattern, 'my.host-name.test', TRUE, 'my.host-name.test');
$array[] = array($pattern, 'qq.ff.ee.my.host-name.test', TRUE, 'qq.ff.ee.my.host-name.test');
$array[] = array($pattern, 'localhost', TRUE, 'localhost');
// 1234567890123456789012345678901234567890123456789012345678901234
$array[] = array($pattern, 'my-yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy-63char.name', TRUE, 'my-yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy-63char.name');
$array[] = array($pattern, 'external.asd1230-123.asd_internal.asd.gm-_ail.com', TRUE, 'external.asd1230-123.asd_internal.asd.gm-_ail.com');
// Domain name IDN
$array[] = array($pattern, 'xn--b1agh1afp.xn--p1ai', TRUE, 'xn--b1agh1afp.xn--p1ai'); // привет.рф
$array[] = array($pattern, 'привет.рф', TRUE, 'привет.рф'); // привет.рф
// Domain name invalid
$array[] = array($pattern, '::127.32.67.15', FALSE);
$array[] = array($pattern, '1.2.3', FALSE);
$array[] = array($pattern, '1.2.3.4', FALSE);
$array[] = array($pattern, '.1.2.3', FALSE);
$array[] = array($pattern, '1.2.3.4.5.6.7.8', FALSE);
$array[] = array($pattern, '999.999.999.999', FALSE);
$array[] = array($pattern, '299.299.299.299', FALSE);
$array[] = array($pattern, '001.002.003.004', FALSE);
$array[] = array($pattern, 'test', FALSE);
$array[] = array($pattern, 'example..com', FALSE);
$array[] = array($pattern, 'http://example.com', FALSE);
$array[] = array($pattern, 'subdomain.-example.com', FALSE);
$array[] = array($pattern, 'example.com/parameter', FALSE);
$array[] = array($pattern, 'example.com?anything', FALSE);
$array[] = array($pattern, 'GigabitEthernet0/1.ServiceInstance.206', FALSE);
// 1234567890123456789012345678901234567890123456789012345678901234
$array[] = array($pattern, 'my-yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy-64char.name', FALSE);
// Domain name in strings
$array[] = array($pattern, '"my.host-name.test"', TRUE, 'my.host-name.test');
$array[] = array($pattern, '(my.host-name.test)', TRUE, 'my.host-name.test');
$array[] = array($pattern, '(my.host-name.test, help)', TRUE, 'my.host-name.test');
$array[] = array($pattern, 'Invalid user test from my.host-name.test', TRUE, 'my.host-name.test');
$array[] = array($pattern, 'Invalid user test from my.host-name.test hs', TRUE, 'my.host-name.test');
$array[] = array($pattern, 'Invalid user test from my.host-name.test.', TRUE, 'my.host-name.test');
$pattern = OBS_PATTERN_EMAIL_FULL;
// Email valid
$array[] = array($pattern, 'president@whitehouse.gov', TRUE, 'president@whitehouse.gov');
$array[] = array($pattern, 'pharaoh@egyptian.museum', TRUE, 'pharaoh@egyptian.museum');
$array[] = array($pattern, 'john.doe+test@ee.my.host-name.test', TRUE, 'john.doe+test@ee.my.host-name.test');
$array[] = array($pattern, 'Mike.O\'Dell@ireland.com', TRUE, 'Mike.O\'Dell@ireland.com');
$array[] = array($pattern, '"Mike\\\\ O\'Dell"@ireland.com', TRUE, '"Mike\\\\ O\'Dell"@ireland.com');
// 1234567890123456789012345678901234567890123456789012345678901234
$array[] = array($pattern, 'user-----------------------------------------------------63char@my-yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy-63char.name', TRUE,
'user-----------------------------------------------------63char@my-yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy-63char.name');
//$array[] = array($pattern, 'external.asd1230-123.asd_internal.asd.gm-_ail.com', TRUE, 'external.asd1230-123.asd_internal.asd.gm-_ail.com');
// Email IDN
$array[] = array($pattern, 'mike@xn--b1agh1afp.xn--p1ai', TRUE, 'mike@xn--b1agh1afp.xn--p1ai'); // mike@привет.рф
$array[] = array($pattern, 'майк@привет.рф', TRUE, 'майк@привет.рф'); // майк@привет.рф
// Email invalid
$array[] = array($pattern, '1024x768@60Hz', FALSE);
$array[] = array($pattern, 'not.a.valid.email', FALSE);
$array[] = array($pattern, 'john@example...com', FALSE);
$array[] = array($pattern, 'joe@ha!ha!.com', FALSE);
// 1234567890123456789012345678901234567890123456789012345678901234
$array[] = array($pattern, 'joe@a_domain_name_with_more_than_sixty-four_characters_is_invalid_6465.com', FALSE);
$array[] = array($pattern, 'a_local_part_with_more_than_sixty-four_characters_is_invalid_6465@mail.com', FALSE);
//$array[] = array($pattern, 'the_total_length_of_an_email_address_is_limited@two-hundred-fifty-four-characters.because-the-SMTP-protocol-for-sending-email.does-not-support-more-than-that.really-hard-to-come-up-with-a-bogus-address-as-long-as-this.still-not-long-enough.too-long-now.com', FALSE);
// Email in strings
$array[] = array($pattern, '"test@domain.name"', TRUE, 'test@domain.name');
$array[] = array($pattern, '(test@domain.name)', TRUE, 'test@domain.name');
$array[] = array($pattern, '(test@domain.name, help)', TRUE, 'test@domain.name');
$array[] = array($pattern, 'The email address president@whitehouse.gov is valid.', TRUE, 'president@whitehouse.gov');
$array[] = array($pattern, 'fabio@disapproved.solutions has a long TLD', TRUE, 'fabio@disapproved.solutions');
$pattern = OBS_PATTERN_EMAIL_LONG_FULL;
// Email valid
$array[] = array($pattern, '<test@domain.name>', TRUE, '<test@domain.name>');
$array[] = array($pattern, 'Pharaoh <pharaoh@egyptian.museum>', TRUE, 'Pharaoh <pharaoh@egyptian.museum>');
$array[] = array($pattern, 'in Egypt "Pharaoh" <pharaoh@egyptian.museum>', TRUE, '"Pharaoh" <pharaoh@egyptian.museum>');
$array[] = array($pattern, 'Pharaoh of Egypt <pharaoh@egyptian.museum>', TRUE, 'Pharaoh of Egypt <pharaoh@egyptian.museum>');
$array[] = array($pattern, '"Mike O\'Dell" <Mike.O\'Dell@ireland.com>', TRUE, '"Mike O\'Dell" <Mike.O\'Dell@ireland.com>');
// Email invalid
$array[] = array($pattern, '<domain.name>', FALSE);
$array[] = array($pattern, 'Pharaoh <pharaoh@>', FALSE);
$array[] = array($pattern, 'Test Title test@example.com', FALSE);
/*
$pattern = OBS_PATTERN_URL_FULL;
// URL IDN
$array[] = array($pattern, 'https://www.get.no/v3/bredb%C3%A5nd/tr%C3%A5dl%C3%B8st-modem', TRUE,
'https://www.get.no/v3/bredb%C3%A5nd/tr%C3%A5dl%C3%B8st-modem');
// URL in string
$array[] = array($pattern, '<a href="https://www.get.no/v3/bredb%C3%A5nd/tr%C3%A5dl%C3%B8st-modem" rel="nofollow">https://www.get.no/v3/bredbånd/trådløst-modem</a>', TRUE,
'https://www.get.no/v3/bredb%C3%A5nd/tr%C3%A5dl%C3%B8st-modem');
*/
$pattern = OBS_PATTERN_LATLON;
$array[] = [ $pattern, 'Some location [33.234, -56.22]', TRUE,
[ 0 => '[33.234, -56.22]', 'lat' => '33.234', 1 => '33.234', 'lon' => '-56.22', 2 => '-56.22' ] ];
$array[] = [ $pattern, 'Some location (33.234 -56.22)', TRUE,
[ 0 => '(33.234 -56.22)', 'lat' => '33.234', 1 => '33.234', 'lon' => '-56.22', 2 => '-56.22' ] ];
$array[] = [ $pattern, ' Some location [33.234;-56.22]', TRUE,
[ 0 => '[33.234;-56.22]', 'lat' => '33.234', 1 => '33.234', 'lon' => '-56.22', 2 => '-56.22' ] ];
$array[] = [ $pattern, '33.234,-56.22', TRUE,
[ 0 => '33.234,-56.22', 'lat' => '33.234', 1 => '33.234', 'lon' => '-56.22', 2 => '-56.22' ] ];
$array[] = [ $pattern, "'33.234','-56.22'", TRUE,
[ 0 => "'33.234','-56.22'", 'lat' => '33.234', 1 => '33.234', 'lon' => '-56.22', 2 => '-56.22' ] ];
$array[] = [ $pattern, 'Some location|47.616380|-122.341673', FALSE ];
$pattern = OBS_PATTERN_LATLON_ALT;
$array[] = [ $pattern, 'Some location|47.616380|-122.341673', TRUE,
[ 0 => '|47.616380|-122.341673', 'lat' => '47.616380', 1 => '47.616380', 'lon' => '-122.341673', 2 => '-122.341673' ] ];
$array[] = [ $pattern, "Some location|'47.616380'|'-122.341673'", TRUE,
[ 0 => "|'47.616380'|'-122.341673'", 'lat' => '47.616380', 1 => '47.616380', 'lon' => '-122.341673', 2 => '-122.341673' ] ];
$array[] = [ $pattern, 'Some location [33.234, -56.22]', FALSE ];
$pattern = OBS_PATTERN_NOPRINT;
// Not printable chars
$array[] = array($pattern, "ABC \n", TRUE);
$array[] = array($pattern, "ABC \r", TRUE);
$array[] = array($pattern, "ABC \t", TRUE);
// All printable
$array[] = array($pattern, "ABC ËЙЦ 10 œ∑√∫Ω≈∆µ \"',.:`~!@#$%^&*()_+-=<>?/[]{}|\\", FALSE);
return $array;
}
/**
* @dataProvider providerDefinitionXss
* @group security
*/
public function testDefinitionXss($string, $result = TRUE) {
$test = preg_match(OBS_PATTERN_XSS, $string);
$this->assertSame($result, (bool)$test);
}
public function providerDefinitionXss() {
$array = [];
// Examples:
// https://notes.offsec-journey.com/owasp-top-10-exploitation/cross-site-scripting-xss
// https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/XSS%20Injection
// script
$array[] = [ 'javascript:alert(document.domain);' ];
$array[] = [ '<a href=\'javascript:alert(1)\'' ];
$array[] = [ 'sCripT>alert(1)</sCripT>' ];
$array[] = [ '<scr<script>ipt>alert(1)</scri</script>pt>' ];
$array[] = [ '<script<script >alert(1)</script</script> >' ];
$array[] = [ '<script>prompt("XSS")</script>' ];
$array[] = [ '"<script/src=data:,alert(1)>' ];
$array[] = [ '<h1> test </h1> <script> alert(1) </script>' ];
$array[] = [ '<sCrIpT> < / s c r i p t >' ];
$array[] = [ 'javascript:alert("Hello world");/' ];
// on*
$array[] = [ '<a onmouseover="alert(1)">TEST</a>' ];
$array[] = [ '<a onmouseout=alert(1)>TEST</a>' ];
$array[] = [ '<a onmousemove=alert(1)>TEST</a>' ];
$array[] = [ '<a onmouseclick=alert(1)>TEST</a>' ];
$array[] = [ '<img src=\'zzzz\' onerror=alert(1)></img>' ];
$array[] = [ '<svg onload=alert(document.domain)>' ];
$array[] = [ '<div> onmouseover=alert(1)></div>' ];
$array[] = [ '<style/onload=alert(document.domain)>' ];
$array[] = [ 'XXX" onmouseover=alert(1) "xx' ];
// iframe
$array[] = [ '><iframe src="data:text/html;base64,base64_data"></iframe>' ];
// eval
$array[] = [ 'eval(String.fromCharCode(97,108,101,114,116,40,49,41))' ];
$array[] = [ '<script>eval("al"%2b"ert(1)")</script>' ];
$array[] = [ '><details ontoggle=eval(atob(\'YWxlcnQoMSk=\')) open>' ];
$array[] = [ 'eval(atob(\'PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg==\'));' ];
// js concat + '' +
$array[] = [ "a'+alert(123)+'a" ];
$array[] = [ "a'+alert()+'a" ];
$array[] = [ "a'+alert`1`+'a" ];
return $array;
}
}
// EOF

View File

@ -2,7 +2,7 @@
//define('OBS_DEBUG', 2);
include(__DIR__ . '/../includes/sql-config.inc.php');
include(__DIR__ . '/../includes/observium.inc.php');
//include(dirname(__FILE__) . '/../includes/defaults.inc.php');
//include(dirname(__FILE__) . '/../config.php');
//include(dirname(__FILE__) . '/../includes/definitions.inc.php');
@ -75,7 +75,7 @@ class IncludesEncryptTest extends \PHPUnit\Framework\TestCase
$result = array();
for ($i=0; $i<20; $i++)
{
$string = generate_random_string(mt_rand(20, 40), $charlist);
$string = random_string(mt_rand(20, 40), $charlist);
$result[] = array($string);
}
return $result;
@ -226,8 +226,8 @@ class IncludesEncryptTest extends \PHPUnit\Framework\TestCase
$result = array();
for ($i=0; $i<20; $i++)
{
$string = generate_random_string(mt_rand(20, 40), $charlist);
$key = generate_random_string(mt_rand(4, 8));
$string = random_string(mt_rand(20, 40), $charlist);
$key = random_string(mt_rand(4, 8));
$result[] = array($string, $key);
}
return $result;
@ -235,16 +235,16 @@ class IncludesEncryptTest extends \PHPUnit\Framework\TestCase
public function providerEncryptSodiumRandom() {
$charlist = ' 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`~!@#$%^&*()_+-=[]{}\|/?,.<>;:"'."'";
$string = generate_random_string(mt_rand(20, 40), $charlist);
$string = random_string(mt_rand(20, 40), $charlist);
$result = array();
if (OBS_ENCRYPT_MODULE === 'sodium') {
$result[] = array( $string, generate_random_string(SODIUM_CRYPTO_SECRETBOX_KEYBYTES - 1), generate_random_string(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES - 1) );
$result[] = array( $string, generate_random_string(SODIUM_CRYPTO_SECRETBOX_KEYBYTES - 1), generate_random_string(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES) );
$result[] = array( $string, generate_random_string(SODIUM_CRYPTO_SECRETBOX_KEYBYTES - 1), generate_random_string(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + 1) );
$result[] = array( $string, generate_random_string(SODIUM_CRYPTO_SECRETBOX_KEYBYTES), generate_random_string(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES - 1) );
$result[] = array( $string, generate_random_string(SODIUM_CRYPTO_SECRETBOX_KEYBYTES), generate_random_string(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES) );
$result[] = array( $string, generate_random_string(SODIUM_CRYPTO_SECRETBOX_KEYBYTES), generate_random_string(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + 1) );
$result[] = array($string, random_string(SODIUM_CRYPTO_SECRETBOX_KEYBYTES - 1), random_string(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES - 1) );
$result[] = array($string, random_string(SODIUM_CRYPTO_SECRETBOX_KEYBYTES - 1), random_string(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES) );
$result[] = array($string, random_string(SODIUM_CRYPTO_SECRETBOX_KEYBYTES - 1), random_string(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + 1) );
$result[] = array($string, random_string(SODIUM_CRYPTO_SECRETBOX_KEYBYTES), random_string(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES - 1) );
$result[] = array($string, random_string(SODIUM_CRYPTO_SECRETBOX_KEYBYTES), random_string(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES) );
$result[] = array($string, random_string(SODIUM_CRYPTO_SECRETBOX_KEYBYTES), random_string(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + 1) );
//$result[] = array($string, generate_random_string(SODIUM_CRYPTO_SECRETBOX_KEYBYTES + 1), generate_random_string(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES - 1));
//$result[] = array($string, generate_random_string(SODIUM_CRYPTO_SECRETBOX_KEYBYTES + 1), generate_random_string(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES));
//$result[] = array($string, generate_random_string(SODIUM_CRYPTO_SECRETBOX_KEYBYTES + 1), generate_random_string(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + 1));

View File

@ -2,78 +2,269 @@
//define('OBS_DEBUG', 2);
include(dirname(__FILE__) . '/../includes/sql-config.inc.php');
//include(dirname(__FILE__) . '/../includes/defaults.inc.php');
//include(dirname(__FILE__) . '/../config.php');
//include(dirname(__FILE__) . '/../includes/definitions.inc.php');
//include(dirname(__FILE__) . '/../includes/functions.inc.php');
include(__DIR__ . '/../includes/defaults.inc.php');
//include(dirname(__FILE__) . '/../config.php'); // Do not include user editable config here
include(__DIR__ . "/../includes/polyfill.inc.php");
include(__DIR__ . "/../includes/autoloader.inc.php");
include(__DIR__ . "/../includes/debugging.inc.php");
require_once(__DIR__ ."/../includes/constants.inc.php");
include(__DIR__ . '/../includes/common.inc.php');
include(__DIR__ . '/../includes/definitions.inc.php');
include(__DIR__ . '/data/test_definitions.inc.php'); // Fake definitions for testing
include(__DIR__ . '/../includes/functions.inc.php');
class IncludesEntitiesTest extends \PHPUnit\Framework\TestCase
{
class IncludesEntitiesTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider providerEntityDescrDefinition
* @group descr
*/
public function testEntityDescrDefinition($type, $result, $definition, $descr_entry, $count = 1)
{
$this->assertSame($result, entity_descr_definition($type, $definition, $descr_entry, $count));
}
/**
* @dataProvider providerEntityDescrDefinition
* @group descr
*/
public function testEntityDescrDefinition($type, $result, $definition, $descr_entry, $count = 1) {
$this->assertSame($result, entity_descr_definition($type, $definition, $descr_entry, $count));
}
public function providerEntityDescrDefinition()
{
$result = array();
public function providerEntityDescrDefinition() {
$result = array();
// Mempool
$type = 'mempool';
$definition = array();
$array = array('i' => '22', 'index' => '33');
// Mempool
$type = 'mempool';
$definition = array();
$array = array('i' => '22', 'index' => '33');
// Defaults from entity definition
$result[] = array($type, 'Memory', $definition, $array);
$result[] = array($type, 'Memory Pool 33', $definition, $array, 2);
// Defaults from entity definition
$result[] = array($type, 'Memory', $definition, $array);
$result[] = array($type, 'Memory Pool 33', $definition, $array, 2);
// Descr from oid_descr, but it empty
$definition['oid_descr'] = 'OidName';
$result[] = array($type, 'Memory', $definition, $array);
// Descr from descr
$definition['descr'] = 'Name from Descr';
$result[] = array($type, 'Name from Descr', $definition, $array);
$result[] = array($type, 'Name from Descr 33', $definition, $array, 2);
// Descr from oid_descr
$array['OidName'] = 'Name from Oid';
$result[] = array($type, 'Name from Oid', $definition, $array);
$result[] = array($type, 'Name from Oid', $definition, $array, 2);
// Now descr use tags
$definition['descr'] = 'Name from Descr with Tags (%i%) {%index%} [%oid_descr%]';
$result[] = array($type, 'Name from Descr with Tags (22) {33} [Name from Oid]', $definition, $array);
$definition['descr'] = 'Name from Descr with Tags (%OidName%)';
$result[] = array($type, 'Name from Descr with Tags (Name from Oid)', $definition, $array);
// Tag multiple times
$definition['descr'] = 'Name from Descr with multiple Tags {%oid_descr%} [%oid_descr%]';
$result[] = array($type, 'Name from Descr with multiple Tags {Name from Oid} [Name from Oid]', $definition, $array);
// Multipart indexes
$definition['descr'] = 'Name from Descr with Tags {%index0%}';
$result[] = array($type, 'Name from Descr with Tags {33}', $definition, $array);
$array['index'] = '11.22.33.44.55';
$definition['descr'] = 'Name from Descr with Multipart Index {%index1%} {%index3%} {%index2%} [%index%]';
$result[] = array($type, 'Name from Descr with Multipart Index {22} {44} {33} [11.22.33.44.55]', $definition, $array);
// Descr from oid_descr, but it empty
$definition['oid_descr'] = 'OidName';
$result[] = array($type, 'Memory', $definition, $array);
// Descr from descr
$definition['descr'] = 'Name from Descr';
$result[] = array($type, 'Name from Descr', $definition, $array);
$result[] = array($type, 'Name from Descr 33', $definition, $array, 2);
// Descr from oid_descr
$array['OidName'] = 'Name from Oid';
$result[] = array($type, 'Name from Oid', $definition, $array);
$result[] = array($type, 'Name from Oid', $definition, $array, 2);
// Now descr use tags
$definition['descr'] = 'Name from Descr with Tags (%i%) {%index%} [%oid_descr%]';
$result[] = array($type, 'Name from Descr with Tags (22) {33} [Name from Oid]', $definition, $array);
$definition['descr'] = 'Name from Descr with Tags (%OidName%)';
$result[] = array($type, 'Name from Descr with Tags (Name from Oid)', $definition, $array);
// Tag multiple times
$definition['descr'] = 'Name from Descr with multiple Tags {%oid_descr%} [%oid_descr%]';
$result[] = array($type, 'Name from Descr with multiple Tags {Name from Oid} [Name from Oid]', $definition, $array);
// Multipart indexes
$definition['descr'] = 'Name from Descr with Tags {%index0%}';
$result[] = array($type, 'Name from Descr with Tags {33}', $definition, $array);
$array['index'] = '11.22.33.44.55';
$definition['descr'] = 'Name from Descr with Multipart Index {%index1%} {%index3%} {%index2%} [%index%]';
$result[] = array($type, 'Name from Descr with Multipart Index {22} {44} {33} [11.22.33.44.55]', $definition, $array);
// Sensors
$type = 'sensor';
$definition = array();
$array = array('i' => '22', 'index' => '33');
// Sensors
$type = 'sensor';
$definition = array();
$array = array('i' => '22', 'index' => '33');
$definition['oid_descr'] = 'jnxOperatingDescr';
$definition['descr_transform'] = ['action' => 'entity_name'];
$definition['oid_descr'] = 'jnxOperatingDescr';
$definition['descr_transform'] = ['action' => 'entity_name'];
$array['jnxOperatingDescr'] = "PIC: 4x 10GE(LAN) SFP+ @ 0/0/*";
$result[] = array($type, 'PIC: 4x 10GE(LAN) SFP+ @ 0/0/*', $definition, $array);
$array['jnxOperatingDescr'] = "PIC: 4x 10GE(LAN) SFP+ @ 0/0/*";
$result[] = array($type, 'PIC: 4x 10GE(LAN) SFP+ @ 0/0/*', $definition, $array);
return $result;
}
return $result;
}
/**
* @dataProvider providerGetDeviceSnmpArgv
* @group device
*/
public function testGetDeviceSnmpArgv($argv, $result, $options = []) {
$this->assertSame($result, get_device_snmp_argv($argv, $snmp_options));
if ($snmp_options || $options) {
// Common snmp v3 or context
$this->assertSame($options, $snmp_options);
}
}
public function providerGetDeviceSnmpArgv() {
$array = [];
// SNMP v1
// hostname.test community v1
$array[] = [ [ 'hostname.test', 'community', 'v1' ],
[ 'hostname' => 'hostname.test', 'snmp_community' => [ 'community' ], 'snmp_version' => 'v1', 'snmp_transport' => 'udp', 'snmp_port' => 161 ] ];
// hostname.test community v1 tcp context
$array[] = [ [ 'hostname.test', 'community', 'v1', 'tcp', 'context' ],
[ 'hostname' => 'hostname.test', 'snmp_community' => [ 'community' ], 'snmp_version' => 'v1', 'snmp_transport' => 'tcp', 'snmp_port' => 161 ],
[ 'snmp_context' => 'context' ] ];
// SNMP v2c (default)
// hostname.test community
$array[] = [ [ 'hostname.test', 'community', ],
[ 'hostname' => 'hostname.test', 'snmp_community' => [ 'community' ], 'snmp_version' => 'v2c', 'snmp_transport' => 'udp', 'snmp_port' => 161 ] ];
// hostname.test community v2c
$array[] = [ [ 'hostname.test', 'community', 'v2c' ],
[ 'hostname' => 'hostname.test', 'snmp_community' => [ 'community' ], 'snmp_version' => 'v2c', 'snmp_transport' => 'udp', 'snmp_port' => 161 ] ];
// hostname.test community v2c tcp context
$array[] = [ [ 'hostname.test', 'community', 'v2c', 'tcp', 'context' ],
[ 'hostname' => 'hostname.test', 'snmp_community' => [ 'community' ], 'snmp_version' => 'v2c', 'snmp_transport' => 'tcp', 'snmp_port' => 161 ],
[ 'snmp_context' => 'context' ] ];
// SNMP v3
// hostname.test nanp v3 username
$snmp_v3_auth = [ [ 'authlevel' => 'noAuthNoPriv', 'authname' => 'username' ] ];
$array[] = [ [ 'hostname.test', 'nanp', 'v3', 'username' ],
[ 'hostname' => 'hostname.test', 'snmp_v3_auth' => $snmp_v3_auth, 'snmp_version' => 'v3', 'snmp_transport' => 'udp', 'snmp_port' => 161 ] ];
// hostname.test nanp v3 tcp context
$snmp_v3_auth = [ [ 'authlevel' => 'noAuthNoPriv', 'authname' => 'observium' ] ];
$array[] = [ [ 'hostname.test', 'nanp', 'v3', 'tcp', 'context' ],
[ 'hostname' => 'hostname.test', 'snmp_v3_auth' => $snmp_v3_auth, 'snmp_version' => 'v3', 'snmp_transport' => 'tcp', 'snmp_port' => 161 ],
[ 'snmp_context' => 'context' ] ];
// hostname.test anp v3 username password sha
$snmp_v3_auth = [ [ 'authlevel' => 'authNoPriv', 'authname' => 'username', 'authpass' => 'password', 'authalgo' => 'sha' ] ];
$array[] = [ [ 'hostname.test', 'anp', 'v3', 'username', 'password', 'sha' ],
[ 'hostname' => 'hostname.test', 'snmp_v3_auth' => $snmp_v3_auth, 'snmp_version' => 'v3', 'snmp_transport' => 'udp', 'snmp_port' => 161 ] ];
// hostname.test anp v3 username password tcp context
$snmp_v3_auth = [ [ 'authlevel' => 'authNoPriv', 'authname' => 'username', 'authpass' => 'password', 'authalgo' => 'MD5' ] ];
$array[] = [ [ 'hostname.test', 'anp', 'v3', 'username', 'password', 'tcp', 'context' ],
[ 'hostname' => 'hostname.test', 'snmp_v3_auth' => $snmp_v3_auth, 'snmp_version' => 'v3', 'snmp_transport' => 'tcp', 'snmp_port' => 161 ],
[ 'snmp_context' => 'context' ] ];
// hostname.test ap v3 username password encpass sha des
$snmp_v3_auth = [ [ 'authlevel' => 'authPriv', 'authname' => 'username', 'authpass' => 'password', 'authalgo' => 'sha', 'cryptopass' => 'encpass', 'cryptoalgo' => 'des' ] ];
$array[] = [ [ 'hostname.test', 'ap', 'v3', 'username', 'password', 'encpass', 'sha', 'des' ],
[ 'hostname' => 'hostname.test', 'snmp_v3_auth' => $snmp_v3_auth, 'snmp_version' => 'v3', 'snmp_transport' => 'udp', 'snmp_port' => 161 ] ];
// hostname.test ap v3 username password encpass tcp context
$snmp_v3_auth = [ [ 'authlevel' => 'authPriv', 'authname' => 'username', 'authpass' => 'password', 'authalgo' => 'MD5', 'cryptopass' => 'encpass', 'cryptoalgo' => 'AES' ] ];
$array[] = [ [ 'hostname.test', 'ap', 'v3', 'username', 'password', 'encpass', 'tcp', 'context' ],
[ 'hostname' => 'hostname.test', 'snmp_v3_auth' => $snmp_v3_auth, 'snmp_version' => 'v3', 'snmp_transport' => 'tcp', 'snmp_port' => 161 ],
[ 'snmp_context' => 'context' ] ];
// SNMP port
// hostname.test:123 community
$array[] = [ [ 'hostname.test:123', 'community' ],
[ 'hostname' => 'hostname.test', 'snmp_community' => [ 'community' ], 'snmp_version' => 'v2c', 'snmp_transport' => 'udp', 'snmp_port' => 123 ] ];
// 127.0.0.1:123 community
$array[] = [ [ '127.0.0.1:123', 'community', 'v2c' ],
[ 'hostname' => '127.0.0.1', 'snmp_community' => [ 'community' ], 'snmp_version' => 'v2c', 'snmp_transport' => 'udp', 'snmp_port' => 123 ] ];
// hostname.test community v2c 123
$array[] = [ [ 'hostname.test', 'community', 'v2c', '123' ],
[ 'hostname' => 'hostname.test', 'snmp_community' => [ 'community' ], 'snmp_version' => 'v2c', 'snmp_transport' => 'udp', 'snmp_port' => 123 ] ];
// ::1 community v2c 123
$array[] = [ [ '::1', 'community', 'v2c', '123' ],
[ 'hostname' => '::1', 'snmp_community' => [ 'community' ], 'snmp_version' => 'v2c', 'snmp_transport' => 'udp', 'snmp_port' => 123 ] ];
// Only hostname/ip for detect all possible params
// hostname.test
$array[] = [ [ 'hostname.test' ],
[ 'hostname' => 'hostname.test', 'snmp_version' => NULL, 'snmp_transport' => 'udp', 'snmp_port' => 161 ] ];
// 127.0.0.1
$array[] = [ [ '127.0.0.1' ],
[ 'hostname' => '127.0.0.1', 'snmp_version' => NULL, 'snmp_transport' => 'udp', 'snmp_port' => 161 ] ];
return $array;
}
/**
* @dataProvider providerIsModuleEnabled
* @group device
*/
public function testIsModuleEnabled($device, $module, $default, $enabled, $disabled, $attrib = TRUE) {
$process = 'poller';
// Pseudo cache for attribs:
$GLOBALS['cache']['entity_attribs_all']['device'][$device['device_id']] = []; // set array, for skip query db
// Check definition(s)
$orig = $GLOBALS['config']['poller_modules'][$module];
$this->assertSame($default, is_module_enabled($device, $module, $process));
$GLOBALS['config']['poller_modules'][$module] = 1;
$this->assertSame($enabled, is_module_enabled($device, $module, $process));
$GLOBALS['config']['poller_modules'][$module] = 0;
$this->assertSame($disabled, is_module_enabled($device, $module, $process));
$GLOBALS['config']['poller_modules'][$module] = $orig;
if ($module === 'os') { return; } // os ignore attrib
// Check attrib
$setting_name = 'poll_' . $module;
$GLOBALS['cache']['entity_attribs']['device'][$device['device_id']][$setting_name] = '1'; // attrib true
if ($attrib) {
$this->assertTrue(is_module_enabled($device, $module, $process));
} else {
$this->assertFalse(is_module_enabled($device, $module, $process));
}
$GLOBALS['cache']['entity_attribs']['device'][$device['device_id']][$setting_name] = '0'; // attrib false
$this->assertFalse(is_module_enabled($device, $module, $process));
}
public function providerIsModuleEnabled() {
$device_linux = [ 'device_id' => 999, 'os' => 'linux', 'os_group' => 'unix' ];
$device_win = [ 'device_id' => 998, 'os' => 'windows' ];
$device_ios = [ 'device_id' => 997, 'os' => 'ios', 'os_group' => 'cisco', 'type' => 'network' ];
$device_vrp = [ 'device_id' => 996, 'os' => 'vrp', 'type' => 'network' ];
$device_amm = [ 'device_id' => 995, 'os' => 'ibm-amm' ]; // poller/discovery blacklists
$device_gen = [ 'device_id' => 994, 'os' => 'generic' ];
$device_aruba = [ 'device_id' => 993, 'os' => 'arubaos', 'type' => 'wireless' ];
$result = [];
$result[] = [ $device_linux, 'os', TRUE, TRUE, TRUE ];
$result[] = [ $device_win, 'os', TRUE, TRUE, TRUE ];
$result[] = [ $device_ios, 'os', TRUE, TRUE, TRUE ];
$result[] = [ $device_vrp, 'os', TRUE, TRUE, TRUE ];
$result[] = [ $device_amm, 'os', TRUE, TRUE, TRUE ];
$result[] = [ $device_gen, 'os', TRUE, TRUE, TRUE ];
$result[] = [ $device_linux, 'unix-agent', FALSE, TRUE, FALSE ];
$result[] = [ $device_win, 'unix-agent', FALSE, FALSE, FALSE, FALSE ];
$result[] = [ $device_ios, 'unix-agent', FALSE, FALSE, FALSE, FALSE ];
$result[] = [ $device_vrp, 'unix-agent', FALSE, FALSE, FALSE, FALSE ];
$result[] = [ $device_amm, 'unix-agent', FALSE, FALSE, FALSE, FALSE ];
//$result[] = [ $device_gen, 'unix-agent', FALSE, TRUE, FALSE ];
$result[] = [ $device_linux, 'ipmi', TRUE, TRUE, FALSE ];
$result[] = [ $device_win, 'ipmi', TRUE, TRUE, FALSE ];
$result[] = [ $device_ios, 'ipmi', FALSE, FALSE, FALSE, FALSE ];
$result[] = [ $device_vrp, 'ipmi', FALSE, FALSE, FALSE, FALSE ];
$result[] = [ $device_amm, 'ipmi', TRUE, TRUE, FALSE ];
$result[] = [ $device_gen, 'ipmi', TRUE, TRUE, FALSE ];
$result[] = [ $device_linux, 'ports', TRUE, TRUE, FALSE ];
$result[] = [ $device_win, 'ports', TRUE, TRUE, FALSE ];
$result[] = [ $device_ios, 'ports', TRUE, TRUE, FALSE ];
$result[] = [ $device_vrp, 'ports', TRUE, TRUE, FALSE ];
$result[] = [ $device_amm, 'ports', FALSE, FALSE, FALSE, FALSE ];
$result[] = [ $device_gen, 'ports', TRUE, TRUE, FALSE ];
$result[] = [ $device_linux, 'wifi', FALSE, FALSE, FALSE ];
$result[] = [ $device_win, 'wifi', FALSE, FALSE, FALSE ];
$result[] = [ $device_ios, 'wifi', TRUE, TRUE, FALSE ];
$result[] = [ $device_vrp, 'wifi', TRUE, TRUE, FALSE ];
$result[] = [ $device_amm, 'wifi', FALSE, FALSE, FALSE ];
$result[] = [ $device_gen, 'wifi', FALSE, FALSE, FALSE ];
$result[] = [ $device_aruba, 'wifi', TRUE, TRUE, FALSE ];
foreach ([ 'cipsec-tunnels', 'cisco-ipsec-flow-monitor', 'cisco-remote-access-monitor',
'cisco-cef', 'cisco-cbqos', 'cisco-eigrp', /*'cisco-vpdn'*/ ] as $module) {
$result[] = [ $device_linux, $module, FALSE, FALSE, FALSE, FALSE ];
$result[] = [ $device_win, $module, FALSE, FALSE, FALSE, FALSE ];
$result[] = [ $device_ios, $module, TRUE, TRUE, FALSE ];
$result[] = [ $device_vrp, $module, FALSE, FALSE, FALSE, FALSE ];
$result[] = [ $device_amm, $module, FALSE, FALSE, FALSE, FALSE ];
$result[] = [ $device_gen, $module, FALSE, FALSE, FALSE, FALSE ];
}
$result[] = [ $device_linux, 'aruba-controller', FALSE, FALSE, FALSE, FALSE ];
$result[] = [ $device_win, 'aruba-controller', FALSE, FALSE, FALSE, FALSE ];
$result[] = [ $device_ios, 'aruba-controller', FALSE, FALSE, FALSE, FALSE ];
$result[] = [ $device_vrp, 'aruba-controller', FALSE, FALSE, FALSE, FALSE ];
$result[] = [ $device_amm, 'aruba-controller', FALSE, FALSE, FALSE, FALSE ];
$result[] = [ $device_gen, 'aruba-controller', FALSE, FALSE, FALSE, FALSE ];
$result[] = [ $device_aruba, 'aruba-controller', TRUE, TRUE, FALSE ];
return $result;
}
}
// EOF

View File

@ -1,16 +1,23 @@
<?php
//define('OBS_DEBUG', 1);
//define('OBS_DEBUG', 2);
$base_dir = realpath(__DIR__ . '/..');
$config['install_dir'] = $base_dir;
include(__DIR__ . '/../includes/defaults.inc.php');
//include(dirname(__FILE__) . '/../config.php'); // Do not include user editable config here
include(__DIR__ . "/../includes/polyfill.inc.php");
include(__DIR__ . "/../includes/autoloader.inc.php");
include(__DIR__ . "/../includes/debugging.inc.php");
require_once(__DIR__ ."/../includes/constants.inc.php");
include(__DIR__ . '/../includes/common.inc.php');
include(__DIR__ . '/data/test_definitions.inc.php'); // Fake definitions for testing
include(__DIR__ . '/../includes/definitions.inc.php');
include(__DIR__ . '/../includes/functions.inc.php');
if (is_file(__DIR__ . '/data/config.php')) {
include(__DIR__ . '/data/config.php'); // I.e. for API keys
}
/**
* @backupGlobals disabled
@ -223,73 +230,174 @@ class IncludesFunctionsTest extends \PHPUnit\Framework\TestCase
);
}
/**
* @dataProvider providerIntAdd
* @group numbers
*/
public function testIntAdd($a, $b, $result)
{
$this->assertSame($result, int_add($a, $b));
}
public function providerIntAdd()
{
// $a = "18446742978492891134"; $b = "0"; $sum = gmp_add($a, $b); echo gmp_strval($sum) . "\n"; // Result: 18446742978492891134
// $a = "18446742978492891134"; $b = "0"; $sum = $a + $b; printf("%.0f\n", $sum); // Result: 18446742978492891136
if (OBS_MATH === 'php')
{
// Fallback (inaccurate math)
$array = array(
array( '18446742978492891134', '0', '18446742978492891136'),
array('-18446742978492891134', '0', '-18446742978492891136'),
array( '18446742978492891134', '18446742978492891134', '36893485956985782272'),
array('-18446742978492891134', '18446742978492891134', '0'),
);
} else {
// Accurate math
$array = array(
array( '18446742978492891134', '0', '18446742978492891134'),
array('-18446742978492891134', '0', '-18446742978492891134'),
array( '18446742978492891134', '18446742978492891134', '36893485956985782268'),
array('-18446742978492891134', '18446742978492891134', '0'),
);
/**
* @dataProvider providerIntAdd
* @group numbers
*/
public function testIntAdd($a, $b, $result) {
$this->assertSame($result, int_add($a, $b));
}
return $array;
}
/**
* @dataProvider providerIntSub
* @group numbers
*/
public function testIntSub($a, $b, $result)
{
$this->assertSame($result, int_sub($a, $b));
}
public function providerIntAdd() {
// $a = "18446742978492891134"; $b = "0"; $sum = gmp_add($a, $b); echo gmp_strval($sum) . "\n"; // Result: 18446742978492891134
// $a = "18446742978492891134"; $b = "0"; $sum = $a + $b; printf("%.0f\n", $sum); // Result: 18446742978492891136
// Accurate math
return [
array( '18446742978492891134', '0', '18446742978492891134'),
array('-18446742978492891134', '0', '-18446742978492891134'),
array( '18446742978492891134', '18446742978492891134', '36893485956985782268'),
array('-18446742978492891134', '18446742978492891134', '0'),
public function providerIntSub()
{
if (OBS_MATH === 'php')
{
// Fallback (inaccurate math)
$array = array(
array( '18446742978492891134', '0', '18446742978492891136'),
array('-18446742978492891134', '0', '-18446742978492891136'),
array( '18446742978492891134', '18446742978492891134', '0'),
array('-18446742978492891134', '18446742978492891134', '-36893485956985782272'),
// Floats
[ '1111111111111111111111111.6', 0, '1111111111111111111111112' ],
[ 0, '1111111111111111111111111.6', '1111111111111111111111112' ],
[ '18446742978492891134.3', '18446742978492891134.6', '36893485956985782269' ],
);
} else {
// Accurate math
$array = array(
array( '18446742978492891134', '0', '18446742978492891134'),
array('-18446742978492891134', '0', '-18446742978492891134'),
array( '18446742978492891134', '18446742978492891134', '0'),
array('-18446742978492891134', '18446742978492891134', '-36893485956985782268'),
);
// numbers with comma
[ '7,619,627.6010', 0, '7619628' ],
[ 0, '7,619,627.6010', '7619628' ],
];
}
/**
* @dataProvider providerIntSub
* @group numbers
*/
public function testIntSub($a, $b, $result) {
$this->assertSame($result, int_sub($a, $b));
}
public function providerIntSub() {
// Accurate math
return [
array( '18446742978492891134', '0', '18446742978492891134'),
array('-18446742978492891134', '0', '-18446742978492891134'),
array( '18446742978492891134', '18446742978492891134', '0'),
array('-18446742978492891134', '18446742978492891134', '-36893485956985782268'),
// Floats
[ '1111111111111111111111111.6', 0, '1111111111111111111111112' ],
[ 0, '1111111111111111111111111.6', '-1111111111111111111111112' ],
[ '-18446742978492891134.3', '18446742978492891134.6', '-36893485956985782269' ],
// numbers with comma
[ '7,619,627.6010', 0, '7619628' ],
[ 0, '7,619,627.6010', '-7619628' ],
];
}
/**
* @dataProvider providerFloatDiv
* @group numbers
*/
public function testFloatDiv($a, $b, $result) {
if (method_exists($this, 'assertEqualsWithDelta')) {
$this->assertEqualsWithDelta($result, float_div($a, $b), 0.00001);
} else {
$this->assertSame($result, float_div($a, $b));
}
}
public function providerFloatDiv() {
// Accurate math
return [
[ '18446742978492891134', '0', 0 ],
[ '-18446742978492891134', '0', 0 ],
[ '18446742978492891134', '18446742978492891134', 1.0 ],
[ '-18446742978492891134', '18446742978492891134', -1.0 ],
// Floats
[ '1111111111111111111111111.6', 0, 0 ],
[ 0, '1111111111111111111111111.6', 0 ],
[ '18446742978492891134.3', '18446742978492891134.6', 1.0 ],
// numbers with comma
[ '7,619,627.6010', 0, 0 ],
[ 0, '7,619,627.6010', 0 ],
[ '1,192.0036', 6.3, 189.20692 ]
];
}
/**
* @dataProvider providerFloatPow
* @group numbers
*/
public function testFloatPow($a, $b, $result) {
if (method_exists($this, 'assertEqualsWithDelta')) {
$this->assertEqualsWithDelta($result, float_pow($a, $b), 0.00001);
} else {
$this->assertSame($result, float_pow($a, $b));
}
}
public function providerFloatPow() {
// Accurate math
return [
[ '18446742978492891134', '0', 1.0 ],
[ '-18446742978492891134', '0', 1.0 ],
[ '0', '18446742978492891134', 0 ],
[ '0', '-18446742978492891134', 0 ],
// negative power
[ 0, -1, 0 ],
[ 0, -1.1, 0 ],
// Floats
[ '11.6', 0, 1.0 ],
[ 0, '11.6', 0 ],
[ '34.3', '4.6', 11543910.531516898 ],
// numbers with comma
[ '7,619,627.6010', 0, 1.0 ],
[ 0, '7,619,627.6010', 0 ],
[ '1,192.0036', 1.3, 9980.696216867238 ]
];
}
/**
* @dataProvider providerHexToFloat
* @group numbers
*/
public function testHexToFloat($hex, $result)
{
$this->assertSame($result, hex2float($hex));
}
public function providerHexToFloat()
{
// Accurate math
$array = [
[ '429241f0', 73.1287841796875 ],
];
return $array;
}
/**
* @dataProvider providerIeeeIntToFloat
* @group numbers
*/
public function testIeeeIntToFloat($int, $result)
{
$this->assertSame($result, ieeeint2float($int));
}
public function providerIeeeIntToFloat()
{
$array = [
[ 1070575314, 1.6225225925445557 ],
[ 2998520959, -2.1629828594882383E-8 ],
[ '1070575314', 1.6225225925445557 ],
[ hexdec('429241f0'), 73.1287841796875 ],
[ 0, 0.0 ],
];
return $array;
}
return $array;
}
/**
* @dataProvider providerIsHexString
@ -297,7 +405,7 @@ class IncludesFunctionsTest extends \PHPUnit\Framework\TestCase
*/
public function testIsHexString($string, $result)
{
$this->assertSame($result, isHexString($string));
$this->assertSame($result, is_hex_string($string));
}
public function providerIsHexString()
@ -329,6 +437,8 @@ class IncludesFunctionsTest extends \PHPUnit\Framework\TestCase
array('Input 1', '496e7075742031'),
array('J}4=', '4a7d343d'),
array('Simple String', '53696d706c6520537472696e67'),
array('PC$rnu', '504324726e75'),
array('Pärnu', '50c3a4726e75'),
);
return $results;
}
@ -584,6 +694,44 @@ class IncludesFunctionsTest extends \PHPUnit\Framework\TestCase
return $results;
}
/**
* @dataProvider providerGetBitsStateArray
* @group states_bits
*/
/* WiP
public function testGetBitsStateArray($hex, $mib, $object, $result)
{
$this->assertSame($result, get_bits_state_array($hex, $mib, $object));
}
public function providerGetBitsStateArray()
{
$results = array(
array('40 00', 'CISCO-STACK-MIB', 'portAdditionalOperStatus', [ 1 => 'connected' ]), // CISCO-STACK-MIB::portAdditionalOperStatus.1.1 = BITS: 40 00 connected(1)
);
return $results;
}
*/
/**
* @dataProvider providerGetBitsStateArray2
* @group states_bits
*/
/* WiP
public function testGetBitsStateArray2($hex, $def, $result)
{
$this->assertSame($result, get_bits_state_array($hex, NULL, NULL, $def));
}
public function providerGetBitsStateArray2()
{
$results = array(
array('40 00', [], [ 1 => 'connected' ]), // CISCO-STACK-MIB::portAdditionalOperStatus.1.1 = BITS: 40 00 connected(1)
);
return $results;
}
*/
/**
* @dataProvider providerPriorityStringToNumeric
*/
@ -910,44 +1058,44 @@ class IncludesFunctionsTest extends \PHPUnit\Framework\TestCase
return $array;
}
/**
* @dataProvider providerGetIpType
* @group ip
*/
public function testGetIpType($ip, $result)
{
$this->assertSame($result, get_ip_type($ip));
}
public function providerGetIpType()
{
return array(
array('0.0.0.0', 'unspecified'),
array('::', 'unspecified'),
array('10.255.255.255/32', 'private'), // Do not set /31 and /32 as broadcast!
array('10.255.255.255/31', 'private'), // Do not set /31 and /32 as broadcast!
array('10.255.255.255/8', 'broadcast'),
array('127.0.0.1', 'loopback'),
array('::1', 'loopback'),
array('0:0:0:0:0:0:0:1/128', 'loopback'),
array('10.12.0.3', 'private'),
array('172.16.1.1', 'private'),
array('192.168.0.3', 'private'),
array('fdf8:f53b:82e4::53', 'private'),
array('0:0:0:0:0:ffff:c000:22f', 'ipv4mapped'),
array('::ffff:192.0.2.47', 'ipv4mapped'),
array('77.222.50.30', 'unicast'),
array('2a02:408:7722:5030::5030', 'unicast'),
array('169.254.2.47', 'link-local'),
array('fe80::200:5aee:feaa:20a2', 'link-local'),
array('2001:0000:4136:e378:8000:63bf:3fff:fdd2', 'teredo'),
array('198.18.0.1', 'benchmark'),
array('2001:0002:0:6C::430', 'benchmark'),
array('2001:10:240:ab::a', 'orchid'),
array('1:0002:6c::430', 'reserved'),
array('ff02::1:ff8b:4d51/0', 'multicast'),
);
}
/**
* @dataProvider providerGetIpType
* @group ip
*/
public function testGetIpType($ip, $result) {
$this->assertSame($result, get_ip_type($ip));
}
public function providerGetIpType() {
return [
[ '0.0.0.0', 'unspecified' ],
[ '::', 'unspecified' ],
[ '10.255.255.255/32', 'private' ], // Do not set /31 and /32 as broadcast!
[ '10.255.255.255/31', 'private' ], // Do not set /31 and /32 as broadcast!
[ '10.255.255.255/8', 'broadcast' ],
[ '127.0.0.1', 'loopback' ],
[ '::1', 'loopback' ],
[ '0:0:0:0:0:0:0:1/128', 'loopback' ],
[ '10.12.0.3', 'private' ],
[ '172.16.1.1', 'private' ],
[ '192.168.0.3', 'private' ],
[ 'fdf8:f53b:82e4::53', 'private' ],
[ '100.80.76.30', 'cgnat' ],
[ '100.105.0.49', 'cgnat' ],
[ '0:0:0:0:0:ffff:c000:22f', 'ipv4mapped' ],
[ '::ffff:192.0.2.47', 'ipv4mapped' ],
[ '77.222.50.30', 'unicast' ],
[ '2a02:408:7722:5030::5030', 'unicast' ],
[ '169.254.2.47', 'link-local' ],
[ 'fe80::200:5aee:feaa:20a2', 'link-local' ],
[ '2001:0000:4136:e378:8000:63bf:3fff:fdd2', 'teredo' ],
[ '198.18.0.1', 'benchmark' ],
[ '2001:0002:0:6C::430', 'benchmark' ],
[ '2001:10:240:ab::a', 'orchid' ],
[ '1:0002:6c::430', 'reserved' ],
[ 'ff02::1:ff8b:4d51/0', 'multicast' ],
];
}
/**
* @dataProvider providerMatchNetwork
@ -971,7 +1119,7 @@ class IncludesFunctionsTest extends \PHPUnit\Framework\TestCase
"10.11.30.0/23", "10.11.32.0/24", "10.11.33.0/24", "10.11.34.0/24", "10.11.41.0/24", "10.11.42.0/24",
"10.11.43.0/24", "10.11.51.0/24", "10.11.52.0/24", "10.11.53.0/24", "10.11.61.0/24", "10.11.62.0/24");
$results = array(
return array(
// Only IPv4 nets
array(TRUE, '127.0.0.1', $nets1),
array(FALSE, '1.1.1.1', $nets1), // not in ranges
@ -1006,12 +1154,51 @@ class IncludesFunctionsTest extends \PHPUnit\Framework\TestCase
// Are you stupid? YES :)
array(FALSE, '172.16.6.6', $nets6),
array(FALSE, 'FE80:FFFF:0:FFFF:129:144:52:38', $nets6),
// Issue test
// Issues test
array(FALSE, '10.52.25.254', $nets8),
array(TRUE, '10.52.25.254', [ '!217.66.159.18' ]),
array(FALSE, '217.66.159.18', [ '!217.66.159.18' ]),
array(TRUE, '217.66.159.18', [ '217.66.159.18' ]),
);
return $results;
}
/**
* @dataProvider providerStringQuoted
* @group string
*/
/* WIP
public function testStringQuoted($string, $result)
{
$this->assertSame($result, is_string_quoted($string));
}
public function providerStringQuoted()
{
return array(
array('\"sdfslfkm s\'fdsf" a;lm aamjn ', FALSE),
array('sdfslfkm s\'fdsf" a;lm aamjn \"', FALSE),
array('sdfslfkm s\'fdsf" a;lm aamjn ', FALSE),
array('\"sdfslfkm s\'fdsf" a;lm aamjn \"', TRUE),
array('"sdfslfkm s\'fdsf" a;lm aamjn "', TRUE),
array('"\"sdfslfkm s\'fdsf" a;lm aamjn \""', TRUE),
array('\'\"sdfslfkm s\'fdsf" a;lm aamjn \"\'', TRUE),
array(' \'\"sdfslfkm s\'fdsf" a;lm aamjn \"\' ', TRUE),
array('"""sdfslfkm s\'fdsf" a;lm aamjn """', TRUE),
array('"""sdfslfkm s\'fdsf" a;lm aamjn """"""""', TRUE),
array('"""""""sdfslfkm s\'fdsf" a;lm aamjn """', TRUE),
// escaped quotes
array('\"Mike Stupalov\" <mike@observium.org>', FALSE),
// utf-8
array('Avenue Léon, België ', FALSE),
array('\"Avenue Léon, België \"', TRUE),
array('"Винни пух и все-все-все "', TRUE),
// multilined
array(' \'\"\"sdfslfkm s\'fdsf"
a;lm aamjn \"\"\' ', TRUE),
);
}
*/
/**
* @dataProvider providerStringTransform
* @group string
@ -1222,55 +1409,53 @@ class IncludesFunctionsTest extends \PHPUnit\Framework\TestCase
$array3),
);
}
/**
* @dataProvider providerIsPingable
* @group network
*/
public function testIsPingable($result, $hostname, $try_a = TRUE)
{
if (!is_executable($GLOBALS['config']['fping']))
{
// CentOS 6.8
$GLOBALS['config']['fping'] = '/usr/sbin/fping';
$GLOBALS['config']['fping6'] = '/usr/sbin/fping6';
}
$flags = OBS_DNS_ALL;
if (!$try_a) { $flags ^= OBS_DNS_A; }
$ping = is_pingable($hostname, $flags);
$ping = is_numeric($ping) && $ping > 0; // Function return random float number
$this->assertSame($result, $ping);
}
public function providerIsPingable()
{
$array = array(
array(TRUE, 'localhost'),
array(TRUE, '127.0.0.1'),
array(FALSE, 'yohoho.i.butylka.roma'),
array(FALSE, '127.0.0.1', FALSE), // Try ping IPv4 with IPv6 disabled
);
$cmd = $GLOBALS['config']['fping6'] . " -c 1 -q ::1 2>&1";
exec($cmd, $output, $return); // Check if we have IPv6 support in current system
if ($return === 0)
{
// IPv6 only
//$array[] = array(TRUE, 'localhost', FALSE);
$array[] = array(TRUE, '::1', FALSE);
$array[] = array(FALSE, '::ffff', FALSE);
foreach (array('localhost', 'ip6-localhost') as $hostname)
{
// Debian used ip6-localhost instead localhost.. lol
$ip = gethostbyname6($hostname, OBS_DNS_AAAA);
if ($ip)
{
$array[] = array(TRUE, $hostname, FALSE);
//var_dump($hostname);
break;
/**
* @dataProvider providerIsPingable
* @group network
*/
public function testIsPingable($hostname, $result, $try_a = TRUE) {
if (!is_executable($GLOBALS['config']['fping'])) {
// CentOS 6.8
$GLOBALS['config']['fping'] = '/usr/sbin/fping';
$GLOBALS['config']['fping6'] = '/usr/sbin/fping6';
}
}
if ($try_a) {
$ping = is_pingable($hostname);
} else {
$ping = is_pingable($hostname, 'ipv6');
}
$ping = is_numeric($ping) && $ping > 0; // Function returns random float number
$this->assertSame($result, $ping);
}
public function providerIsPingable() {
$array = [
[ 'localhost', TRUE ],
[ '127.0.0.1', TRUE ],
[ 'yohoho.i.butylka.roma', FALSE ],
[ '127.0.0.1', FALSE, FALSE ], // Try ping IPv4 with IPv6 only
];
$cmd = $GLOBALS['config']['fping6'] . " -c 1 -q ::1 2>&1";
exec($cmd, $output, $return); // Check if we have IPv6 support in a current system
if ($return === 0) {
// IPv6 only
$array[] = [ '::1', TRUE, FALSE ];
$array[] = [ '::ffff', FALSE, FALSE ];
foreach ([ 'localhost', 'ip6-localhost' ] as $hostname) {
// Debian used ip6-localhost instead localhost.. lol
if ($ip = gethostbyname6($hostname, 'ipv6')) {
$array[] = [ $hostname, TRUE, FALSE ];
//var_dump($hostname);
break;
}
}
}
return $array;
}
return $array;
}
/**
* @dataProvider providerCalculateMempoolProperties
@ -1341,6 +1526,194 @@ class IncludesFunctionsTest extends \PHPUnit\Framework\TestCase
);
return $results;
}
/**
* @dataProvider providerGetGeolocation
* @group geo
*/
public function testGetGeolocation($address, $result, $api = 'geocodefarm', $geo_db = [], $dns_only = FALSE)
{
if ($api === 'geocodefarm' || $api === 'openstreetmap' ||
!empty($GLOBALS['config']['geo_api'][$api]['key'])) {
$GLOBALS['config']['geocoding']['dns'] = $dns_only;
$GLOBALS['config']['geocoding']['api'] = $api;
$test = get_geolocation($address, $geo_db, $dns_only);
unset($test['location_updated'], $test['location_status']);
$this->assertSame($result, $test);
}
}
public function providerGetGeolocation()
{
$array = [];
// DNS LOC (reverse)
$location = 'qwerty';
$api = 'openstreetmap';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lat' => 37.7749289, 'location_lon' => -122.4194178,
'location_city' => 'San Francisco', 'location_county' => 'Unknown', 'location_state' => 'California', 'location_country' => 'United States' ];
$array[] = [ $location, $result, $api, [ 'hostname' => 'loc-degree.observium.dev' ], TRUE ]; // reverse, dns only
$api = 'geocodefarm';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lat' => 37.7749289, 'location_lon' => -122.4194178,
'location_city' => 'Mission District', 'location_county' => 'San Francisco', 'location_state' => 'CA', 'location_country' => 'United States' ];
$array[] = [ $location, $result, $api, [ 'hostname' => 'loc-degree.observium.dev' ], TRUE ]; // reverse, dns only
$api = 'yandex';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lat' => 37.7749289, 'location_lon' => -122.4194178,
'location_country' => 'United States', 'location_state' => 'California', 'location_county' => 'San Francisco', 'location_city' => 'SoMa' ];
$array[] = [ $location, $result, $api, [ 'hostname' => 'loc-degree.observium.dev' ], TRUE ]; // reverse, dns only
$api = 'mapquest';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lat' => 37.7749289, 'location_lon' => -122.4194178,
'location_city' => 'San Francisco', 'location_county' => 'San Francisco', 'location_state' => 'CA', 'location_country' => 'United States' ];
$array[] = [ $location, $result, $api, [ 'hostname' => 'loc-degree.observium.dev' ], TRUE ]; // reverse, dns only
$api = 'bing';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lat' => 37.7749289, 'location_lon' => -122.4194178,
'location_city' => 'Mission District', 'location_county' => 'San Francisco', 'location_state' => 'California', 'location_country' => 'United States' ];
$array[] = [ $location, $result, $api, [ 'hostname' => 'loc-degree.observium.dev' ], TRUE ]; // reverse, dns only
// Location (reverse)
$location = 'Some location [47.616380;-122.341673]';
$api = 'openstreetmap';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lat' => 47.61638, 'location_lon' => -122.341673,
'location_city' => 'Seattle', 'location_county' => 'King', 'location_state' => 'Washington', 'location_country' => 'United States' ];
$array[] = [ $location, $result, $api ];
$location = 'Some location|\'47.616380\'|\'-122.341673\'';
$api = 'openstreetmap';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lat' => 47.61638, 'location_lon' => -122.341673,
'location_city' => 'Seattle', 'location_county' => 'King', 'location_state' => 'Washington', 'location_country' => 'United States' ];
$array[] = [ $location, $result, $api ];
// First request (forward)
$location = 'Badenerstrasse 569, Zurich, Switzerland';
$api = 'openstreetmap';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lat' => 47.3832766, 'location_lon' => 8.4955511,
'location_city' => 'Zurich', 'location_county' => 'District Zurich', 'location_state' => 'Zurich', 'location_country' => 'Switzerland' ];
$array[] = [ $location, $result, $api ];
$location = 'Nikhef, Amsterdam, NL';
$api = 'yandex';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lon' => 4.892557, 'location_lat' => 52.373057,
'location_country' => 'Netherlands', 'location_state' => 'North Holland', 'location_county' => 'North Holland', 'location_city' => 'Amsterdam' ];
$array[] = [ $location, $result, $api ];
$location = 'Korea_Seoul';
$api = 'mapquest';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lat' => 37.55886, 'location_lon' => 126.99989,
'location_city' => 'Seoul', 'location_county' => 'South Korea', 'location_state' => 'Unknown', 'location_country' => 'South Korea' ];
$array[] = [ $location, $result, $api ];
// Second request (forward)
$location = 'ZRH2, Badenerstrasse 569, Zurich, Switzerland';
$api = 'openstreetmap';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lat' => 47.3832766, 'location_lon' => 8.4955511,
'location_city' => 'Zurich', 'location_county' => 'District Zurich', 'location_state' => 'Zurich', 'location_country' => 'Switzerland' ];
$array[] = [ $location, $result, $api ];
$location = 'Rack: NK-76 - Nikhef, Amsterdam, NL';
$api = 'yandex';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lon' => 4.892557, 'location_lat' => 52.373057,
'location_country' => 'Netherlands', 'location_state' => 'North Holland', 'location_county' => 'North Holland', 'location_city' => 'Amsterdam' ];
$array[] = [ $location, $result, $api ];
$location = 'Korea_Seoul';
$api = 'bing';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lat' => 37.5682945, 'location_lon' => 126.9977875,
'location_city' => 'Seoul', 'location_county' => 'Unknown', 'location_state' => 'Seoul', 'location_country' => 'South Korea' ];
$array[] = [ $location, $result, $api ];
return $array;
}
/**
* @group sql
*/
public function testGenerateWhereClauseWithValidConditions()
{
$conditions = [
'column1 = "value1"',
'',
' ',
'column2 > 10'
];
$additional_conditions = [
'column3 < 50',
'column4 LIKE "%example%"'
];
$expected = ' WHERE column1 = "value1" AND column2 > 10 AND column3 < 50 AND column4 LIKE "%example%"';
$result = generate_where_clause($conditions, $additional_conditions);
$this->assertEquals($expected, $result);
}
/**
* @group sql
*/
public function testGenerateWhereClauseWithOnlyEmptyConditions()
{
$conditions = [
'',
' ',
"\t",
"\n"
];
$result = generate_where_clause($conditions);
//$this->assertNull($result);
$this->assertEquals('', $result);
}
/**
* @group sql
*/
public function testGenerateWhereClauseWithSingleCondition()
{
$conditions = [
'column1 = "value1"'
];
$expected = ' WHERE column1 = "value1"';
$result = generate_where_clause($conditions);
$this->assertEquals($expected, $result);
}
/**
* @group sql
*/
public function testGenerateWhereClauseWithNoConditions()
{
$conditions = [];
$result = generate_where_clause($conditions);
//$this->assertNull($result);
$this->assertEquals('', $result);
}
/**
* @group sql
*/
public function testGenerateWhereClauseWithOnlyAdditionalConditions()
{
$conditions = [];
$additional_conditions = [
'column1 = "value1"',
'column2 > 10'
];
$expected = ' WHERE column1 = "value1" AND column2 > 10';
$result = generate_where_clause($conditions, $additional_conditions);
$this->assertEquals($expected, $result);
}
}
// EOF

View File

@ -5,6 +5,10 @@ $config['install_dir'] = $base_dir;
include(__DIR__ . '/../includes/defaults.inc.php');
//include(dirname(__FILE__) . '/../config.php'); // Do not include user editable config here
include(__DIR__ . "/../includes/polyfill.inc.php");
include(__DIR__ . "/../includes/autoloader.inc.php");
include(__DIR__ . "/../includes/debugging.inc.php");
require_once(__DIR__ ."/../includes/constants.inc.php");
include(__DIR__ . '/../includes/common.inc.php');
include(__DIR__ . '/../includes/definitions.inc.php');
include(__DIR__ . '/data/test_definitions.inc.php'); // Fake definitions for testing

View File

@ -9,6 +9,10 @@ $config['install_dir'] = $base_dir;
// Base observium includes
include(__DIR__ . '/../includes/defaults.inc.php');
//include(dirname(__FILE__) . '/../config.php'); // Do not include user editable config here
include(__DIR__ . "/../includes/polyfill.inc.php");
include(__DIR__ . "/../includes/autoloader.inc.php");
include(__DIR__ . "/../includes/debugging.inc.php");
require_once(__DIR__ ."/../includes/constants.inc.php");
include(__DIR__ . '/../includes/common.inc.php');
include(__DIR__ . '/../includes/definitions.inc.php');
include(__DIR__ . '/data/test_definitions.inc.php'); // Fake definitions for testing
@ -60,7 +64,7 @@ class IncludesRewritesTest extends \PHPUnit\Framework\TestCase
public function providerRewriteEntityNameCsv()
{
return new CsvFileIterator(dirname(__FILE__) . '/data/providerRewriteEntityName.csv');
return new CsvFileIterator(__DIR__ . '/data/providerRewriteEntityName.csv');
}
/**
@ -215,6 +219,7 @@ class IncludesRewritesTest extends \PHPUnit\Framework\TestCase
array('rus', 'Russian Federation'),
array('Russian Federation', 'Russian Federation'),
array('russia', 'Russian Federation'),
array('South Korea', 'South Korea'),
);
}
@ -222,10 +227,10 @@ class IncludesRewritesTest extends \PHPUnit\Framework\TestCase
* @dataProvider providerRewriteDefinitionHardware
* @group hardware
*/
public function testRewriteDefinitionHardware($os, $id, $result)
public function testGetModelParam($os, $id, $result)
{
$device = array('os' => $os, 'sysObjectID' => $id);
$this->assertEquals($result, rewrite_definition_hardware($device));
$this->assertEquals($result, get_model_param($device, 'hardware'));
}
public function providerRewriteDefinitionHardware()
@ -422,85 +427,84 @@ class IncludesRewritesTest extends \PHPUnit\Framework\TestCase
);
}
/**
* @dataProvider providerProcessPortLabel
* @group process
*/
public function testProcessPortLabel($os, $array, $result)
{
// Port array template
$port = array(
'ifIndex' => '5',
//'ifDescr' => 'GigabitEthernet0/1',
'ifType' => 'ethernetCsmacd',
'ifMtu' => '1500',
'ifSpeed' => '1000000000',
'ifPhysAddress' => '4c:4e:35:fb:c7:20',
'ifAdminStatus' => 'up',
'ifOperStatus' => 'up',
'ifLastChange' => '0:0:01:03.68',
'ifInOctets' => '2336423782',
'ifInUcastPkts' => '56523160',
'ifInDiscards' => '0',
'ifInErrors' => '195562',
'ifInUnknownProtos' => '0',
'ifOutOctets' => '2769871040',
'ifOutUcastPkts' => '83292747',
'ifOutDiscards' => '0',
'ifOutErrors' => '0',
//'ifName' => 'Gi0/1',
'ifInMulticastPkts' => '1',
'ifInBroadcastPkts' => '21',
'ifOutMulticastPkts' => '16933',
'ifOutBroadcastPkts' => '2434835',
'ifHCInOctets' => '10926358374',
'ifHCInUcastPkts' => '56523160',
'ifHCInMulticastPkts' => '1',
'ifHCInBroadcastPkts' => '21',
'ifHCOutOctets' => '75784315072',
'ifHCOutUcastPkts' => '83292747',
'ifHCOutMulticastPkts' => '16933',
'ifHCOutBroadcastPkts' => '2434835',
'ifLinkUpDownTrapEnable' => 'enabled',
'ifHighSpeed' => '1000',
'ifPromiscuousMode' => 'false',
'ifConnectorPresent' => 'true',
//'ifAlias' => 'Po1#2',
'ifCounterDiscontinuityTime' => '0:0:00:32.81',
'dot3StatsDuplexStatus' => 'fullDuplex',
);
foreach ($array as $oid => $value)
{
$port[$oid] = $value;
/**
* @dataProvider providerProcessPortLabel
* @group process
*/
public function testProcessPortLabel($os, $array, $result) {
// Port array template
$port = [
'ifIndex' => '5',
//'ifDescr' => 'GigabitEthernet0/1',
'ifType' => 'ethernetCsmacd',
'ifMtu' => '1500',
'ifSpeed' => '1000000000',
'ifPhysAddress' => '4c:4e:35:fb:c7:20',
'ifAdminStatus' => 'up',
'ifOperStatus' => 'up',
'ifLastChange' => '0:0:01:03.68',
'ifInOctets' => '2336423782',
'ifInUcastPkts' => '56523160',
'ifInDiscards' => '0',
'ifInErrors' => '195562',
'ifInUnknownProtos' => '0',
'ifOutOctets' => '2769871040',
'ifOutUcastPkts' => '83292747',
'ifOutDiscards' => '0',
'ifOutErrors' => '0',
//'ifName' => 'Gi0/1',
'ifInMulticastPkts' => '1',
'ifInBroadcastPkts' => '21',
'ifOutMulticastPkts' => '16933',
'ifOutBroadcastPkts' => '2434835',
'ifHCInOctets' => '10926358374',
'ifHCInUcastPkts' => '56523160',
'ifHCInMulticastPkts' => '1',
'ifHCInBroadcastPkts' => '21',
'ifHCOutOctets' => '75784315072',
'ifHCOutUcastPkts' => '83292747',
'ifHCOutMulticastPkts' => '16933',
'ifHCOutBroadcastPkts' => '2434835',
'ifLinkUpDownTrapEnable' => 'enabled',
'ifHighSpeed' => '1000',
'ifPromiscuousMode' => 'false',
'ifConnectorPresent' => 'true',
//'ifAlias' => 'Po1#2',
'ifCounterDiscontinuityTime' => '0:0:00:32.81',
'dot3StatsDuplexStatus' => 'fullDuplex',
];
foreach ($array as $oid => $value) {
$port[$oid] = $value;
}
// Device array template
$device = [
'device_id' => 99999999,
'os' => $os,
];
// Process $port array
process_port_label($port, $device);
//var_dump($port);
// Select specific entries for validate
$test_array = [];
foreach ([ 'port_label', 'port_label_num', 'port_label_base', 'port_label_short' ] as $oid) {
$test_array[$oid] = $port[$oid];
}
// Additionally, test processing ifAlias on some entries
if (isset($result['ifAlias'])) {
$test_array['ifAlias'] = $port['ifAlias'];
}
$this->assertEquals($result, $test_array);
}
// Device array template
$device = array(
'device_id' => 99999999,
'os' => $os,
);
// Process $port array
process_port_label($port, $device);
//var_dump($port);
public function providerProcessPortLabel() {
// Select specific entries for validate
$test_array = array();
foreach (array('port_label', 'port_label_num', 'port_label_base', 'port_label_short') as $oid)
{
$test_array[$oid] = $port[$oid];
}
// Additionally test processing ifAlias on some entries
if (isset($result['ifAlias']))
{
$test_array['ifAlias'] = $port['ifAlias'];
}
$this->assertEquals($result, $test_array);
}
public function providerProcessPortLabel()
{
return array(
return [
array('ios', array('ifDescr' => 'GigabitEthernet0/1', 'ifName' => 'Gi0/1', 'ifAlias' => 'Po1#2'),
array('port_label' => 'GigabitEthernet0/1', 'port_label_num' => '0/1', 'port_label_base' => 'GigabitEthernet', 'port_label_short' => 'Gi0/1')),
array('ios', array('ifDescr' => 'FastEthernet0/1/1', 'ifName' => 'Fa0/1/1', 'ifAlias' => 'COMSTAR BGP link'),
@ -557,6 +561,11 @@ class IncludesRewritesTest extends \PHPUnit\Framework\TestCase
array('vrp', array('ifDescr' => 'XGigabitEthernet5/0/14', 'ifName' => 'XGigabitEthernet5/0/14', 'ifAlias' => ''),
array('port_label' => 'XGigabitEthernet5/0/14', 'port_label_num' => '5/0/14', 'port_label_base' => 'XGigabitEthernet', 'port_label_short' => 'XGi5/0/14')),
array('hh3c', array('ifDescr' => 'Ten-GigabitEthernet2/0/25', 'ifName' => 'Ten-GigabitEthernet2/0/25', 'ifAlias' => 'Ten-GigabitEthernet2/0/25 Interface'),
array('port_label' => 'Ten-GigabitEthernet2/0/25', 'port_label_num' => '2/0/25', 'port_label_base' => 'Ten-GigabitEthernet', 'port_label_short' => 'Te2/0/25')),
array('hh3c', array('ifDescr' => 'Vlan-interface1504', 'ifName' => 'Vlan-interface1504', 'ifAlias' => ''),
array('port_label' => 'Vlan-interface1504', 'port_label_num' => '1504', 'port_label_base' => 'Vlan-interface', 'port_label_short' => 'Vlan1504')),
array('routeros', array('ifDescr' => 'Core: sfp-sfpplus1- Trunk to 6509', 'ifName' => 'Core: sfp-sfpplus1- Trunk to 6509', 'ifAlias' => ''),
array('port_label' => 'Core: sfp-sfpplus1- Trunk to 6509', 'port_label_num' => '', 'port_label_base' => 'Core: sfp-sfpplus1- Trunk to 6509', 'port_label_short' => 'Core: sfp-sfpplus1- Trunk to 6509')),
@ -567,6 +576,15 @@ class IncludesRewritesTest extends \PHPUnit\Framework\TestCase
array('linux', array('ifDescr' => 'eth0.101', 'ifName' => 'eth0.101', 'ifAlias' => ''),
array('port_label' => 'eth0.101', 'port_label_num' => '0.101', 'port_label_base' => 'eth', 'port_label_short' => 'eth0.101')),
[ 'pve', [ 'ifDescr' => 'veth101i0', 'ifName' => 'veth101i0', 'ifAlias' => '' ],
[ 'port_label' => 'veth101i0', 'port_label_num' => '101i0', 'port_label_base' => 'veth', 'port_label_short' => 'veth101i0' ] ],
[ 'openbsd', [ 'ifDescr' => 'vether1', 'ifName' => 'vether1', 'ifAlias' => '' ],
[ 'port_label' => 'vether1', 'port_label_num' => '1', 'port_label_base' => 'vether', 'port_label_short' => 'vether1' ] ],
[ 'generic', [ 'ifDescr' => 'veth1bbfdc5', 'ifName' => 'veth1bbfdc5', 'ifAlias' => '' ],
[ 'port_label' => 'veth1bbfdc5', 'port_label_num' => '1bbfdc5', 'port_label_base' => 'veth', 'port_label_short' => 'veth1bbfdc5' ] ],
[ 'nutanix', [ 'ifDescr' => 'vethfd3fe3c0', 'ifName' => 'vethfd3fe3c0', 'ifAlias' => '' ],
[ 'port_label' => 'vethfd3fe3c0', 'port_label_num' => 'fd3fe3c0', 'port_label_base' => 'veth', 'port_label_short' => 'vethfd3fe3c0' ] ],
// port_label os definitions
array('vmware', array('ifDescr' => 'Device vmnic7 at 08:00.1 bnx2', 'ifName' => '', 'ifAlias' => ''),
array('port_label' => 'vmnic7', 'port_label_num' => '7', 'port_label_base' => 'vmnic', 'port_label_short' => 'vmnic7')),
@ -621,6 +639,12 @@ class IncludesRewritesTest extends \PHPUnit\Framework\TestCase
array('ekinops-360', array('ifDescr' => 'EKINOPS/C200/1/MGNT/GbE_RJ45#1', 'ifName' => 'EKINOPS/C200/1/MGNT/GbE_RJ45#1', 'ifAlias' => ''),
array('port_label' => '1/MGNT/GbE_RJ45#1', 'port_label_num' => '1', 'port_label_base' => '1/MGNT/GbE_RJ45#', 'port_label_short' => '1/MGNT/GbE_RJ45#1', 'ifAlias' => '')),
// os definition, multiple label_num
[ 'adtran-ta', [ 'ifDescr' => 'Shelf: 1, Slot: 11, Pon: 1, ONT: 1, ONT Serial No: ADTN21296399, ONT Reg ID:', 'ifName' => '', 'ifAlias' => 'Serial No: ADTN21296399' ],
[ 'port_label' => 'ONT 1/11/1/1', 'port_label_num' => '1/11/1/1', 'port_label_base' => 'ONT', 'port_label_short' => 'ONT 1/11/1/1' ] ],
[ 'adtran-ta', [ 'ifDescr' => 'PON-4, Splitter #1 Washington St', 'ifName' => '', 'ifAlias' => 'Splitter #1 Washington St' ],
[ 'port_label' => 'PON-4', 'port_label_num' => '4', 'port_label_base' => 'PON-', 'port_label_short' => 'PON-4' ] ],
// ifType_ifDescr
array('liebert', array('ifDescr' => '', 'ifType' => 'softwareLoopback'), // ++ ifType, ifIndex
array('port_label' => 'Loopback 5', 'port_label_num' => '5', 'port_label_base' => 'Loopback ', 'port_label_short' => 'Lo 5')),
@ -739,8 +763,8 @@ class IncludesRewritesTest extends \PHPUnit\Framework\TestCase
//array('generic', array('ifDescr' => 'microsens'),
// array('port_label' => 'microsens', 'port_label_num' => 'microsens', 'port_label_base' => '', 'port_label_short' => 'microsens')),
);
}
];
}
}
// EOF

View File

@ -1,4 +1,14 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage tests
* @author Observium Limited <http://www.observium.org/>
*
*/
$base_dir = realpath(__DIR__ . '/..');
$config['install_dir'] = $base_dir;
@ -7,6 +17,10 @@ $config['install_dir'] = $base_dir;
include(__DIR__ . '/../includes/defaults.inc.php');
//include(dirname(__FILE__) . '/../config.php'); // Do not include user editable config here
include(__DIR__ . "/../includes/polyfill.inc.php");
include(__DIR__ . "/../includes/autoloader.inc.php");
include(__DIR__ . "/../includes/debugging.inc.php");
require_once(__DIR__ ."/../includes/constants.inc.php");
include(__DIR__ . '/../includes/common.inc.php');
include(__DIR__ . '/../includes/definitions.inc.php');
//include(dirname(__FILE__) . '/data/test_definitions.inc.php'); // Fake definitions for testing
@ -156,63 +170,97 @@ class IncludesSnmpTest extends \PHPUnit\Framework\TestCase
);
}
/**
* @dataProvider providerSnmpFixNumeric
* @group numbers
*/
public function testSnmpFixNumeric($value, $result, $unit)
{
$this->assertSame($result, snmp_fix_numeric($value, $unit));
}
public function providerSnmpFixNumeric()
{
$array = array(
array( 0, 0),
array( '-65000', -65000),
array( '', ''),
array( 'Some.0', 'Some.0'),
array( FALSE, FALSE),
array(4200000066, 4200000066),
// Here numeric fixes
array('"-7"', -7),
array('+7', 7),
array(' 20,4', 20.4),
array('4,200000067', 4.200000067),
array('" -002.4336 dBm: Normal "', -2.4336),
array('"66.1 C (151.0 F)"', 66.1),
array('"36 C/96 F"', 36),
array('"8232W"', 8232),
array('"1628W (+/- 3.0%)"', 1628),
array('3.09(W-)', 3.09),
array('-26.02(A-)', -26.02),
array('-0.00(A-)', 0.0),
// Convert some passed units
array('512 MB', 512),
array('512 MB', 536870912.0, 'bytes'),
array('119.1 GB', 119.1),
array('119.1 GB', 127882651238.4, 'bytes'),
array('0x01', 1, 'hex'),
array('0x00', 0, 'hex'),
// More complex
array('CPU Temperature-Ctlr B: 58 C 136.40F', 58),
array('Capacitor Cell 1 Voltage-Ctlr B: 2.04V', 2.04),
array('Voltage 12V Rail Loc: left-PSU: 12.22V', 12.22),
array('Current 12V Rail Loc: right-PSU: 9.53A', 9.53),
array('Capacitor Charge-Ctlr B: 100%', 100),
array('Spinning at 5160 RPM', 5160),
);
foreach ($array as $index => $entry)
{
if (!isset($entry[2]))
{
$array[$index][] = NULL;
}
/**
* @dataProvider providerSnmpFixNumeric
* @group numbers
*/
public function testSnmpFixNumeric($value, $result, $unit) {
$this->assertSame($result, snmp_fix_numeric($value, $unit));
}
return $array;
}
public function providerSnmpFixNumeric() {
$array = [
array( 0, 0),
array( '-65000', -65000),
array( '', ''),
array( 'Some.0', 'Some.0'),
array( FALSE, FALSE),
array(4200000066, 4200000066),
// Here numeric fixes
array('"-7"', -7),
array('+7', 7),
array(' 20,4', 20.4),
array('4,200000067', 4.200000067),
array('" -002.4336 dBm: Normal "', -2.4336),
array('"66.1 C (151.0 F)"', 66.1),
array('"36 C/96 F"', 36),
array('"8232W"', 8232),
array('"1628W (+/- 3.0%)"', 1628),
array('3.09(W-)', 3.09),
array('-26.02(A-)', -26.02),
array('-0.00(A-)', 0.0),
// SNMP hex string
[ '31 37 2E 33 6B 56 41 00 ', 17.3 ], // 17.3kVA
[ '31 37 2E 33 6B 56 41 00 ', 17300.0, 'units' ], // 17.3kVA
[ '31', 31 ],
// Convert some passed units
array('512 MB', 512),
array('512 MB', 536870912.0, 'bytes'),
array('119.1 GB', 119.1),
array('119.1 GB', 127882651238.4, 'bytes'),
array('0x01', 1, 'hex'),
array('0x00', 0, 'hex'),
[ '17.3kVA', 17.3 ],
[ '17.3kVA', 17300.0, 'units' ],
// More complex
array('CPU Temperature-Ctlr B: 58 C 136.40F', 58),
array('Capacitor Cell 1 Voltage-Ctlr B: 2.04V', 2.04),
array('Voltage 12V Rail Loc: left-PSU: 12.22V', 12.22),
array('Current 12V Rail Loc: right-PSU: 9.53A', 9.53),
array('Capacitor Charge-Ctlr B: 100%', 100),
array('Spinning at 5160 RPM', 5160),
// Split
[ '42.50 ,35.97 ,40.64 ,40.38', 42.5, 'split1' ],
[ '42.50 ,35.97 ,40.64 ,40.38', 35.97, 'split2' ],
[ '42.50 ,35.97 ,40.64 ,40.38', 40.64, 'split3' ],
[ '42.50 ,35.97 ,40.64 ,40.38', 40.38, 'split4' ],
[ 'CPU Load (100ms, 1s, 10s) : 0%, 2%, 3%', 0, 'split1' ],
[ 'CPU Load (100ms, 1s, 10s) : 0%, 2%, 3%', 2, 'split2' ],
[ 'CPU Load (100ms, 1s, 10s) : 0%, 2%, 3%', 3, 'split3' ],
[ " 5 Secs ( 6.510%) 60 Secs ( 7.724%) 300 Secs ( 6.3812%)", 6.510, 'split1' ],
[ " 5 Secs ( 6.510%) 60 Secs ( 7.724%) 300 Secs ( 6.3812%)", 7.724, 'split2' ],
[ " 5 Secs ( 6.510%) 60 Secs ( 7.724%) 300 Secs ( 6.3812%)", 6.3812, 'split3' ],
[ "5 Sec (6.99%), 1 Min (6.72%), 5 Min (9.06%)", 9.06, 'split3' ],
[ "20% (cpu1: 28% cpu2: 13%)", 20 ],
[ "20% (cpu1: 28% cpu2: 13%)", 28, 'split1' ],
[ "20% (cpu1: 28% cpu2: 13%)", 13, 'split2' ],
[ " 6% (cpu1: 5% cpu2: 7%)", 6 ],
[ " 6% (cpu1: 5% cpu2: 7%)", 5, 'split_cpu1' ],
[ " 6% (cpu1: 5% cpu2: 7%)", 7, 'split_cpu2' ],
];
// Split lanes
$split_lanes = '
Lane 1: 1.01 dBm
Lane 2: 1.29 dBm
Lane 3: 2.1 dBm
Lane 4: 2.71 dBm';
$array[] = [ $split_lanes, 1.01, 'split_lane1' ];
$array[] = [ $split_lanes, 1.29, 'split_lane2' ];
$array[] = [ $split_lanes, 2.1, 'split_lane3' ];
$array[] = [ $split_lanes, 2.71, 'split_lane4' ];
foreach ($array as $index => $entry) {
if (!isset($entry[2])) {
$array[$index][] = NULL;
}
}
return $array;
}
/**
* @dataProvider providerSnmpFixString
@ -254,6 +302,8 @@ class IncludesSnmpTest extends \PHPUnit\Framework\TestCase
// UTF-8
array("44 61 74 61 3A 20 41 20 41 64 64 72 65 73 73 3A 20 32 32 35 2E 35 2E 31 2E 36 20 41 6C 69 61 73 3A 20 D0 94 D1 80 D0 B0 D0 B9 D0 B2 20 62 75 66 66 65 72 20 61 64 64 72 65 73 73 20 63 68 61 6E 67 65 64 20 31 31 30 34", 'Data: A Address: 225.5.1.6 Alias: Драйв buffer address changed 1104'),
array("C3 9C 62 65 72 74 72 61 67 75 6E 67 73 77 61 6C 7A 65 2C 20 50 4E 20 31 31 35 52 30 30 31 32 36", "Übertragungswalze, PN 115R00126"),
array("50 43 24 72 6E 75", 'PC$rnu'), // Incorrectly encoded UTF8, see: https://jira.observium.org/browse/OBS-4377
array("50 C3 A4 72 6E 75", "Pärnu"),
// Multiline string
array("67 6F 6F 67 6C 65 2E 73 65 00 6E 61 6D 65 2D 73 65 72 76 65 72 00 31 37 32 2E 31 37 2E 32 30 34 2E 31 30 00", "google.se\nname-server\n172.17.204.10"),
//Incorrect HEX strings

View File

@ -2,234 +2,248 @@
//define('OBS_DEBUG', 1);
include(__DIR__ . '/../includes/sql-config.inc.php');
include(__DIR__ . '/../includes/observium.inc.php');
include(__DIR__ . '../html/includes/functions.inc.php');
class IncludesSyslogTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider providerProcessSyslogLine
* @group process
*/
public function testProcessSyslogLine($line, $result) {
// Create fake device array from syslog line
list($os) = explode('||', $line, 2);
$device = array('hostname' => $os, 'device_id' => crc32($os), 'os' => $os);
if (isset($GLOBALS['config']['os'][$os]['os_group'])) {
$device['os_group'] = $GLOBALS['config']['os'][$os]['os_group'];
}
//var_dump($GLOBALS['config']['os'][$os]);
/**
* @dataProvider providerProcessSyslogLine
* @group process
*/
public function testProcessSyslogLine($line, $result) {
// Create fake device array from syslog line
$os = explode('||', $line, 2)[0];
$device = array('hostname' => $os, 'device_id' => crc32($os), 'os' => $os);
if (isset($GLOBALS['config']['os'][$os]['os_group'])) {
$device['os_group'] = $GLOBALS['config']['os'][$os]['os_group'];
}
//var_dump($GLOBALS['config']['os'][$os]);
// Override device cache for syslog processing:
$host = $device['hostname'];
$dev_cache = array();
$dev_cache[$host]['lastchecked'] = time();
$dev_cache[$host]['device_id'] = $device['device_id'];
$dev_cache[$host]['os'] = $device['os'];
if (isset($device['os_group'])) {
$dev_cache[$host]['os_group'] = $device['os_group'];
}
$GLOBALS['dev_cache'] = $dev_cache;
// Override device cache for syslog processing:
$host = $device['hostname'];
$dev_cache = [];
$dev_cache[$host]['lastchecked'] = time();
$dev_cache[$host]['device_id'] = $device['device_id'];
$dev_cache[$host]['os'] = $device['os'];
if (isset($device['os_group'])) {
$dev_cache[$host]['os_group'] = $device['os_group'];
}
$GLOBALS['dev_cache'] = $dev_cache;
// Override config syslog filter
$GLOBALS['config']['syslog']['filter'] = array('TEST', 'derp');
// Override config syslog filter
$GLOBALS['config']['syslog']['filter'] = [ 'TEST', 'derp' ];
if ($tmp = process_syslog_line($line))
{
// Just custom resort array
$entry = array();
foreach (array('facility', 'priority', 'level', 'tag', // array('host', 'facility', 'priority', 'level', 'tag',
'program', 'msg', 'msg_orig') as $key)
{
$entry[$key] = $tmp[$key];
}
} else {
$entry = $tmp; // FALSE positive
if ($tmp = process_syslog_line($line)) {
// Just custom resort array
$entry = [];
foreach ([ 'facility', 'priority', 'level', 'tag', // [ 'host', 'facility', 'priority', 'level', 'tag',
'program', 'msg', 'msg_orig' ] as $key) {
$entry[$key] = $tmp[$key];
}
} else {
$entry = $tmp; // FALSE positive
}
$this->assertSame($result, $entry);
}
$this->assertSame($result, $entry);
}
public function providerProcessSyslogLine() {
$result = [];
// Linux/Unix
$result[] = [ 'linux||9||6||6||CRON[3196]:||2018-03-13 06:25:01|| (root) CMD (test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ))||CRON',
[ 'facility' => 'cron', 'priority' => '6', 'level' => '6',
'tag' => 'CRON[3196]', 'program' => 'CRON',
'msg' => '(root) CMD (test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ))',
'msg_orig' => '(root) CMD (test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ))', ]
];
$result[] = [ 'linux||4||6||6||sshd[10809]:||2018-03-19 15:28:47|| message repeated 2 times: [ Failed password for root from 221.194.44.211 port 49810 ssh2]||sshd',
[ 'facility' => 'auth', 'priority' => '6', 'level' => '6',
'tag' => 'sshd[10809]', 'program' => 'SSHD',
'msg' => 'Failed password for root from 221.194.44.211 port 49810 ssh2',
'msg_orig' => 'message repeated 2 times: [ Failed password for root from 221.194.44.211 port 49810 ssh2]', ]
];
$result[] = [ 'linux||5||6||6||rsyslogd0:||2018-03-14 06:28:18|| action \'action 18\' resumed (module \'builtin:ompipe\') [try http://www.rsyslog.com/e/0 ]||rsyslogd0',
[ 'facility' => 'syslog', 'priority' => '6', 'level' => '6',
'tag' => 'rsyslogd0', 'program' => 'RSYSLOGD',
'msg' => 'action \'action 18\' resumed (module \'builtin:ompipe\') [try http://www.rsyslog.com/e/0 ]',
'msg_orig' => 'action \'action 18\' resumed (module \'builtin:ompipe\') [try http://www.rsyslog.com/e/0 ]', ]
];
$result[] = [ 'linux||5||4||4||rsyslogd-2007:||2018-03-14 06:55:50|| action \'action 18\' suspended, next retry is Wed Mar 14 06:56:20 2018 [try http://www.rsyslog.com/e/2007 ]||rsyslogd-2007',
[ 'facility' => 'syslog', 'priority' => '4', 'level' => '4',
'tag' => 'rsyslogd-2007', 'program' => 'RSYSLOGD',
'msg' => 'action \'action 18\' suspended, next retry is Wed Mar 14 06:56:20 2018 [try http://www.rsyslog.com/e/2007 ]',
'msg_orig' => 'action \'action 18\' suspended, next retry is Wed Mar 14 06:56:20 2018 [try http://www.rsyslog.com/e/2007 ]', ]
];
$result[] = [ 'linux||9||5||5||run-parts(/etc/cron.hourly)[2654||2021-11-26 08:01:01|| starting 0anacron||run-parts(',
[ 'facility' => 'cron', 'priority' => '5', 'level' => '5',
'tag' => 'run-parts,/etc/cron.hourly', 'program' => '0ANACRON',
'msg' => 'starting 0anacron',
'msg_orig' => 'starting 0anacron', ]
];
$result[] = [ 'linux||3||6||6||fail2ban-client[20598]:||2018-06-07 14:36:03|| 2018-06-07 14:36:03,699 fail2ban.server [20601]: INFO Starting Fail2ban v0.9.3||fail2ban-client',
[ 'facility' => 'daemon', 'priority' => '6', 'level' => '6',
'tag' => 'client,INFO', 'program' => 'FAIL2BAN',
'msg' => 'Starting Fail2ban v0.9.3',
'msg_orig' => '2018-06-07 14:36:03,699 fail2ban.server [20601]: INFO Starting Fail2ban v0.9.3', ]
];
$result[] = [ 'linux||3||6||6||fail2ban-server:||2021-11-12 11:51:25|| Server ready||fail2ban-server',
[ 'facility' => 'daemon', 'priority' => '6', 'level' => '6',
'tag' => 'server', 'program' => 'FAIL2BAN',
'msg' => 'Server ready',
'msg_orig' => 'Server ready', ]
];
$result[] = [ 'linux||3||5||5||fail2ban.actions[4314]:||2021-11-26 11:15:57|| NOTICE [sshd] Unban 116.98.170.132||fail2ban.actions',
[ 'facility' => 'daemon', 'priority' => '5', 'level' => '5',
'tag' => 'actions,NOTICE', 'program' => 'FAIL2BAN',
'msg' => '[sshd] Unban 116.98.170.132',
'msg_orig' => 'NOTICE [sshd] Unban 116.98.170.132', ]
];
// from group definition
$result[] = [ 'linux||10||5||5||sshd[9071]:||2018-03-20 17:40:43|| PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=221.194.47.243 user=root||sshd',
[ 'facility' => 'authpriv', 'priority' => '5', 'level' => '5',
'tag' => 'sshd[9071]', 'program' => 'SSHD',
'msg' => 'PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=221.194.47.243 user=root',
'msg_orig' => 'PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=221.194.47.243 user=root', ]
];
$result[] = [ 'linux||10||5||5||sshd[9071]:||2018-03-20 17:40:43|| pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=221.194.47.243 user=root||sshd',
[ 'facility' => 'authpriv', 'priority' => '5', 'level' => '5',
'tag' => 'sshd[9071],pam_unix,auth', 'program' => 'SSHD',
'msg' => 'pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=221.194.47.243 user=root',
'msg_orig' => 'pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=221.194.47.243 user=root', ]
];
$result[] = [ 'linux||10||5||5||sshd[9071]:||2018-03-20 17:40:43|| pam_krb5[sshd:auth]: authentication failure; logname=root uid=0 euid=0 tty=ssh ruser= rhost=123.213.132.231||sshd',
[ 'facility' => 'authpriv', 'priority' => '5', 'level' => '5',
'tag' => 'sshd[9071],pam_krb5,auth', 'program' => 'SSHD',
'msg' => 'pam_krb5[sshd:auth]: authentication failure; logname=root uid=0 euid=0 tty=ssh ruser= rhost=123.213.132.231',
'msg_orig' => 'pam_krb5[sshd:auth]: authentication failure; logname=root uid=0 euid=0 tty=ssh ruser= rhost=123.213.132.231', ]
];
$result[] = [ 'linux||10||5||5||sshd[9071]:||2018-03-20 17:40:43|| pam_krb5: authentication failure; logname=root uid=0 euid=0 tty=ssh ruser= rhost=123.213.132.231||sshd',
[ 'facility' => 'authpriv', 'priority' => '5', 'level' => '5',
'tag' => 'sshd[9071],pam_krb5', 'program' => 'SSHD',
'msg' => 'pam_krb5: authentication failure; logname=root uid=0 euid=0 tty=ssh ruser= rhost=123.213.132.231',
'msg_orig' => 'pam_krb5: authentication failure; logname=root uid=0 euid=0 tty=ssh ruser= rhost=123.213.132.231', ]
];
$result[] = [ 'freebsd||14||6||6||kernel:||2018-03-21 13:07:05|| Mar 21 13:07:05 somehost syslogd: exiting on signal 15||kernel',
[ 'facility' => 'console', 'priority' => '6', 'level' => '6',
'tag' => 'kernel', 'program' => 'KERNEL',
'msg' => 'somehost syslogd: exiting on signal 15',
'msg_orig' => 'Mar 21 13:07:05 somehost syslogd: exiting on signal 15', ]
];
$result[] = [ 'freebsd||9||6||6||/usr/sbin/cron[19422]:||2018-03-21 13:10:00|| (root) CMD (/usr/libexec/atrun)||',
[ 'facility' => 'cron', 'priority' => '6', 'level' => '6',
'tag' => 'cron[19422]', 'program' => 'CRON',
'msg' => '(root) CMD (/usr/libexec/atrun)',
'msg_orig' => '(root) CMD (/usr/libexec/atrun)', ]
];
$result[] = [ 'freebsd||3||6||6||transmission-daemon[56416]:||2018-03-21 14:53:11|| Сезон 1 Scrape error: Could not connect to tracker (announcer.c:1279) ||transmission-daemon',
[ 'facility' => 'daemon', 'priority' => '6', 'level' => '6',
'tag' => 'transmission-daemon[56416],announcer.c', 'program' => 'TRANSMISSION-DAEMON',
'msg' => 'Сезон 1 Scrape error: Could not connect to tracker (announcer.c:1279)',
'msg_orig' => 'Сезон 1 Scrape error: Could not connect to tracker (announcer.c:1279)', ]
];
$result[] = [ 'linux||3||5||5||dbus[523]:||2021-11-26 11:07:35|| [system] Activating service name=\'org.freedesktop.problems\' (using servicehelper)||dbus',
[ 'facility' => 'daemon', 'priority' => '5', 'level' => '5',
'tag' => 'dbus[523],system', 'program' => 'DBUS',
'msg' => '[system] Activating service name=\'org.freedesktop.problems\' (using servicehelper)',
'msg_orig' => '[system] Activating service name=\'org.freedesktop.problems\' (using servicehelper)', ]
];
public function providerProcessSyslogLine()
{
$result = array();
// Linux/Unix
$result[] = array('linux||9||6||6||CRON[3196]:||2018-03-13 06:25:01|| (root) CMD (test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ))||CRON',
array('facility' => 'cron', 'priority' => '6', 'level' => '6',
'tag' => 'CRON[3196]', 'program' => 'CRON',
'msg' => '(root) CMD (test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ))',
'msg_orig' => '(root) CMD (test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ))',
));
$result[] = array('linux||4||6||6||sshd[10809]:||2018-03-19 15:28:47|| message repeated 2 times: [ Failed password for root from 221.194.44.211 port 49810 ssh2]||sshd',
array('facility' => 'auth', 'priority' => '6', 'level' => '6',
'tag' => 'sshd[10809]', 'program' => 'SSHD',
'msg' => 'Failed password for root from 221.194.44.211 port 49810 ssh2',
'msg_orig' => 'message repeated 2 times: [ Failed password for root from 221.194.44.211 port 49810 ssh2]',
));
$result[] = array('linux||5||6||6||rsyslogd0:||2018-03-14 06:28:18|| action \'action 18\' resumed (module \'builtin:ompipe\') [try http://www.rsyslog.com/e/0 ]||rsyslogd0',
array('facility' => 'syslog', 'priority' => '6', 'level' => '6',
'tag' => 'rsyslogd0', 'program' => 'RSYSLOGD',
'msg' => 'action \'action 18\' resumed (module \'builtin:ompipe\') [try http://www.rsyslog.com/e/0 ]',
'msg_orig' => 'action \'action 18\' resumed (module \'builtin:ompipe\') [try http://www.rsyslog.com/e/0 ]',
));
$result[] = array('linux||5||4||4||rsyslogd-2007:||2018-03-14 06:55:50|| action \'action 18\' suspended, next retry is Wed Mar 14 06:56:20 2018 [try http://www.rsyslog.com/e/2007 ]||rsyslogd-2007',
array('facility' => 'syslog', 'priority' => '4', 'level' => '4',
'tag' => 'rsyslogd-2007', 'program' => 'RSYSLOGD',
'msg' => 'action \'action 18\' suspended, next retry is Wed Mar 14 06:56:20 2018 [try http://www.rsyslog.com/e/2007 ]',
'msg_orig' => 'action \'action 18\' suspended, next retry is Wed Mar 14 06:56:20 2018 [try http://www.rsyslog.com/e/2007 ]',
));
$result[] = [ 'linux||9||5||5||run-parts(/etc/cron.hourly)[2654||2021-11-26 08:01:01|| starting 0anacron||run-parts(',
[ 'facility' => 'cron', 'priority' => '5', 'level' => '5',
'tag' => 'run-parts,/etc/cron.hourly', 'program' => '0ANACRON',
'msg' => 'starting 0anacron',
'msg_orig' => 'starting 0anacron', ]
];
$result[] = [ 'linux||3||6||6||fail2ban-client[20598]:||2018-06-07 14:36:03|| 2018-06-07 14:36:03,699 fail2ban.server [20601]: INFO Starting Fail2ban v0.9.3||fail2ban-client',
[ 'facility' => 'daemon', 'priority' => '6', 'level' => '6',
'tag' => 'client,INFO', 'program' => 'FAIL2BAN',
'msg' => 'Starting Fail2ban v0.9.3',
'msg_orig' => '2018-06-07 14:36:03,699 fail2ban.server [20601]: INFO Starting Fail2ban v0.9.3', ]
];
$result[] = [ 'linux||3||6||6||fail2ban-server:||2021-11-12 11:51:25|| Server ready||fail2ban-server',
[ 'facility' => 'daemon', 'priority' => '6', 'level' => '6',
'tag' => 'server', 'program' => 'FAIL2BAN',
'msg' => 'Server ready',
'msg_orig' => 'Server ready', ]
];
$result[] = [ 'linux||3||5||5||fail2ban.actions[4314]:||2021-11-26 11:15:57|| NOTICE [sshd] Unban 116.98.170.132||fail2ban.actions',
[ 'facility' => 'daemon', 'priority' => '5', 'level' => '5',
'tag' => 'actions,NOTICE', 'program' => 'FAIL2BAN',
'msg' => '[sshd] Unban 116.98.170.132',
'msg_orig' => 'NOTICE [sshd] Unban 116.98.170.132', ]
];
// from group definition
$result[] = array('linux||10||5||5||sshd[9071]:||2018-03-20 17:40:43|| PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=221.194.47.243 user=root||sshd',
array('facility' => 'authpriv', 'priority' => '5', 'level' => '5',
'tag' => 'sshd[9071]', 'program' => 'SSHD',
'msg' => 'PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=221.194.47.243 user=root',
'msg_orig' => 'PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=221.194.47.243 user=root',
));
$result[] = array('linux||10||5||5||sshd[9071]:||2018-03-20 17:40:43|| pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=221.194.47.243 user=root||sshd',
array('facility' => 'authpriv', 'priority' => '5', 'level' => '5',
'tag' => 'sshd[9071],pam_unix,auth', 'program' => 'SSHD',
'msg' => 'pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=221.194.47.243 user=root',
'msg_orig' => 'pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=221.194.47.243 user=root',
));
$result[] = array('linux||10||5||5||sshd[9071]:||2018-03-20 17:40:43|| pam_krb5[sshd:auth]: authentication failure; logname=root uid=0 euid=0 tty=ssh ruser= rhost=123.213.132.231||sshd',
array('facility' => 'authpriv', 'priority' => '5', 'level' => '5',
'tag' => 'sshd[9071],pam_krb5,auth', 'program' => 'SSHD',
'msg' => 'pam_krb5[sshd:auth]: authentication failure; logname=root uid=0 euid=0 tty=ssh ruser= rhost=123.213.132.231',
'msg_orig' => 'pam_krb5[sshd:auth]: authentication failure; logname=root uid=0 euid=0 tty=ssh ruser= rhost=123.213.132.231',
));
$result[] = array('linux||10||5||5||sshd[9071]:||2018-03-20 17:40:43|| pam_krb5: authentication failure; logname=root uid=0 euid=0 tty=ssh ruser= rhost=123.213.132.231||sshd',
array('facility' => 'authpriv', 'priority' => '5', 'level' => '5',
'tag' => 'sshd[9071],pam_krb5', 'program' => 'SSHD',
'msg' => 'pam_krb5: authentication failure; logname=root uid=0 euid=0 tty=ssh ruser= rhost=123.213.132.231',
'msg_orig' => 'pam_krb5: authentication failure; logname=root uid=0 euid=0 tty=ssh ruser= rhost=123.213.132.231',
));
// Another repeated message
$result[] = [ 'freebsd||1||4||4||message||2018-03-21 14:50:37|| repeated 2 times||message', FALSE ];
$result[] = array('freebsd||14||6||6||kernel:||2018-03-21 13:07:05|| Mar 21 13:07:05 somehost syslogd: exiting on signal 15||kernel',
array('facility' => 'console', 'priority' => '6', 'level' => '6',
'tag' => 'kernel', 'program' => 'KERNEL',
'msg' => 'somehost syslogd: exiting on signal 15',
'msg_orig' => 'Mar 21 13:07:05 somehost syslogd: exiting on signal 15',
));
$result[] = array('freebsd||9||6||6||/usr/sbin/cron[19422]:||2018-03-21 13:10:00|| (root) CMD (/usr/libexec/atrun)||',
array('facility' => 'cron', 'priority' => '6', 'level' => '6',
'tag' => 'cron[19422]', 'program' => 'CRON',
'msg' => '(root) CMD (/usr/libexec/atrun)',
'msg_orig' => '(root) CMD (/usr/libexec/atrun)',
));
$result[] = array('freebsd||3||6||6||transmission-daemon[56416]:||2018-03-21 14:53:11|| Сезон 1 Scrape error: Could not connect to tracker (announcer.c:1279) ||transmission-daemon',
array('facility' => 'daemon', 'priority' => '6', 'level' => '6',
'tag' => 'transmission-daemon[56416],announcer.c', 'program' => 'TRANSMISSION-DAEMON',
'msg' => 'Сезон 1 Scrape error: Could not connect to tracker (announcer.c:1279)',
'msg_orig' => 'Сезон 1 Scrape error: Could not connect to tracker (announcer.c:1279)',
));
$result[] = [ 'linux||3||5||5||dbus[523]:||2021-11-26 11:07:35|| [system] Activating service name=\'org.freedesktop.problems\' (using servicehelper)||dbus',
[ 'facility' => 'daemon', 'priority' => '5', 'level' => '5',
'tag' => 'dbus[523],system', 'program' => 'DBUS',
'msg' => '[system] Activating service name=\'org.freedesktop.problems\' (using servicehelper)',
'msg_orig' => '[system] Activating service name=\'org.freedesktop.problems\' (using servicehelper)', ]
];
// Another repeated message
$result[] = array('freebsd||1||4||4||message||2018-03-21 14:50:37|| repeated 2 times||message',
FALSE);
// Windows
$result[] = [ 'windows||3||3||3||Security-Auditing:||2018-03-17 15:53:43|| 4625: AUDIT_FAILURE An account failed to log on. Subject: Security ID: S-1-0-0 Account Name: - Account Domain: - Logon ID: 0x0 Logon Type: 3 Account For Which Logon Failed: Security ID: S-1-0-0 Account Name: ADMINISTRATOR Account Domain: Failure Information: Failure Reason: Unknown user name or bad password. Status: 0xc000006d Sub Status: 0xc000006a Process Information: Caller Process ID: 0x0 Caller Process Name: - Network Information: Workstation Name: Source Network Address: - Source Port: - Detailed Authentication Information: Logon Process: NtLmSsp Authentication Package: NTLM Transited Services: - Package Name (NTLM only): - Key Length: 0 This event is generated when a logon request fails. It is generated on the computer where access was attempted. The Subject fields indicate the account on the local system which requested the logon. This is most commonly a service such as the Server service, or a local process such as Winlogon.exe or Services.exe. The Logon Type field indicates the kind of logon that was requested. The most common types are 2 (interactive) and 3 (network). The Process Information fields indicate which account and process on the system requested the logon. The Network Information fields indicate where a remote logon request originated. Workstation name is not always available and may be left blank in some cases. The authentication information fields provide detailed information about this specific logon request. - Transited services indicate which intermediate services have participated in this logon request. - Package name indicates which sub-protocol was used among the NTLM protocols. - Key length indicates the length of the generated session key. This will be 0 if no session key was requested.||Security-Auditing',
[ 'facility' => 'daemon', 'priority' => '3', 'level' => '3',
'tag' => 'Security-Auditing', 'program' => 'SECURITY-AUDITING',
'msg' => '4625: AUDIT_FAILURE An account failed to log on. Subject: Security ID: S-1-0-0 Account Name: - Account Domain: - Logon ID: 0x0 Logon Type: 3 Account For Which Logon Failed: Security ID: S-1-0-0 Account Name: ADMINISTRATOR Account Domain: Failure Information: Failure Reason: Unknown user name or bad password. Status: 0xc000006d Sub Status: 0xc000006a Process Information: Caller Process ID: 0x0 Caller Process Name: - Network Information: Workstation Name: Source Network Address: - Source Port: - Detailed Authentication Information: Logon Process: NtLmSsp Authentication Package: NTLM Transited Services: - Package Name (NTLM only): - Key Length: 0 This event is generated when a logon request fails. It is generated on the computer where access was attempted. The Subject fields indicate the account on the local system which requested the logon. This is most commonly a service such as the Server service, or a local process such as Winlogon.exe or Services.exe. The Logon Type field indicates the kind of logon that was requested. The most common types are 2 (interactive) and 3 (network). The Process Information fields indicate which account and process on the system requested the logon. The Network Information fields indicate where a remote logon request originated. Workstation name is not always available and may be left blank in some cases. The authentication information fields provide detailed information about this specific logon request. - Transited services indicate which intermediate services have participated in this logon request. - Package name indicates which sub-protocol was used among the NTLM protocols. - Key length indicates the length of the generated session key. This will be 0 if no session key was requested.',
'msg_orig' => '4625: AUDIT_FAILURE An account failed to log on. Subject: Security ID: S-1-0-0 Account Name: - Account Domain: - Logon ID: 0x0 Logon Type: 3 Account For Which Logon Failed: Security ID: S-1-0-0 Account Name: ADMINISTRATOR Account Domain: Failure Information: Failure Reason: Unknown user name or bad password. Status: 0xc000006d Sub Status: 0xc000006a Process Information: Caller Process ID: 0x0 Caller Process Name: - Network Information: Workstation Name: Source Network Address: - Source Port: - Detailed Authentication Information: Logon Process: NtLmSsp Authentication Package: NTLM Transited Services: - Package Name (NTLM only): - Key Length: 0 This event is generated when a logon request fails. It is generated on the computer where access was attempted. The Subject fields indicate the account on the local system which requested the logon. This is most commonly a service such as the Server service, or a local process such as Winlogon.exe or Services.exe. The Logon Type field indicates the kind of logon that was requested. The most common types are 2 (interactive) and 3 (network). The Process Information fields indicate which account and process on the system requested the logon. The Network Information fields indicate where a remote logon request originated. Workstation name is not always available and may be left blank in some cases. The authentication information fields provide detailed information about this specific logon request. - Transited services indicate which intermediate services have participated in this logon request. - Package name indicates which sub-protocol was used among the NTLM protocols. - Key length indicates the length of the generated session key. This will be 0 if no session key was requested.', ]
];
// Windows
$result[] = array('windows||3||3||3||Security-Auditing:||2018-03-17 15:53:43|| 4625: AUDIT_FAILURE An account failed to log on. Subject: Security ID: S-1-0-0 Account Name: - Account Domain: - Logon ID: 0x0 Logon Type: 3 Account For Which Logon Failed: Security ID: S-1-0-0 Account Name: ADMINISTRATOR Account Domain: Failure Information: Failure Reason: Unknown user name or bad password. Status: 0xc000006d Sub Status: 0xc000006a Process Information: Caller Process ID: 0x0 Caller Process Name: - Network Information: Workstation Name: Source Network Address: - Source Port: - Detailed Authentication Information: Logon Process: NtLmSsp Authentication Package: NTLM Transited Services: - Package Name (NTLM only): - Key Length: 0 This event is generated when a logon request fails. It is generated on the computer where access was attempted. The Subject fields indicate the account on the local system which requested the logon. This is most commonly a service such as the Server service, or a local process such as Winlogon.exe or Services.exe. The Logon Type field indicates the kind of logon that was requested. The most common types are 2 (interactive) and 3 (network). The Process Information fields indicate which account and process on the system requested the logon. The Network Information fields indicate where a remote logon request originated. Workstation name is not always available and may be left blank in some cases. The authentication information fields provide detailed information about this specific logon request. - Transited services indicate which intermediate services have participated in this logon request. - Package name indicates which sub-protocol was used among the NTLM protocols. - Key length indicates the length of the generated session key. This will be 0 if no session key was requested.||Security-Auditing',
array('facility' => 'daemon', 'priority' => '3', 'level' => '3',
'tag' => 'Security-Auditing', 'program' => 'SECURITY-AUDITING',
'msg' => '4625: AUDIT_FAILURE An account failed to log on. Subject: Security ID: S-1-0-0 Account Name: - Account Domain: - Logon ID: 0x0 Logon Type: 3 Account For Which Logon Failed: Security ID: S-1-0-0 Account Name: ADMINISTRATOR Account Domain: Failure Information: Failure Reason: Unknown user name or bad password. Status: 0xc000006d Sub Status: 0xc000006a Process Information: Caller Process ID: 0x0 Caller Process Name: - Network Information: Workstation Name: Source Network Address: - Source Port: - Detailed Authentication Information: Logon Process: NtLmSsp Authentication Package: NTLM Transited Services: - Package Name (NTLM only): - Key Length: 0 This event is generated when a logon request fails. It is generated on the computer where access was attempted. The Subject fields indicate the account on the local system which requested the logon. This is most commonly a service such as the Server service, or a local process such as Winlogon.exe or Services.exe. The Logon Type field indicates the kind of logon that was requested. The most common types are 2 (interactive) and 3 (network). The Process Information fields indicate which account and process on the system requested the logon. The Network Information fields indicate where a remote logon request originated. Workstation name is not always available and may be left blank in some cases. The authentication information fields provide detailed information about this specific logon request. - Transited services indicate which intermediate services have participated in this logon request. - Package name indicates which sub-protocol was used among the NTLM protocols. - Key length indicates the length of the generated session key. This will be 0 if no session key was requested.',
'msg_orig' => '4625: AUDIT_FAILURE An account failed to log on. Subject: Security ID: S-1-0-0 Account Name: - Account Domain: - Logon ID: 0x0 Logon Type: 3 Account For Which Logon Failed: Security ID: S-1-0-0 Account Name: ADMINISTRATOR Account Domain: Failure Information: Failure Reason: Unknown user name or bad password. Status: 0xc000006d Sub Status: 0xc000006a Process Information: Caller Process ID: 0x0 Caller Process Name: - Network Information: Workstation Name: Source Network Address: - Source Port: - Detailed Authentication Information: Logon Process: NtLmSsp Authentication Package: NTLM Transited Services: - Package Name (NTLM only): - Key Length: 0 This event is generated when a logon request fails. It is generated on the computer where access was attempted. The Subject fields indicate the account on the local system which requested the logon. This is most commonly a service such as the Server service, or a local process such as Winlogon.exe or Services.exe. The Logon Type field indicates the kind of logon that was requested. The most common types are 2 (interactive) and 3 (network). The Process Information fields indicate which account and process on the system requested the logon. The Network Information fields indicate where a remote logon request originated. Workstation name is not always available and may be left blank in some cases. The authentication information fields provide detailed information about this specific logon request. - Transited services indicate which intermediate services have participated in this logon request. - Package name indicates which sub-protocol was used among the NTLM protocols. - Key length indicates the length of the generated session key. This will be 0 if no session key was requested.',
));
// Cisco IOS
$result[] = [ 'ios||23||5||5||26644:||2013-11-08 07:19:24|| *Mar 1 18:48:50.483 UTC: %SYS-5-CONFIG_I: Configured from console by vty2 (10.34.195.36)||26644',
[ 'facility' => 'local7', 'priority' => '5', 'level' => '5',
'tag' => 'CONFIG_I', 'program' => 'SYS',
'msg' => 'Configured from console by vty2 (10.34.195.36)',
'msg_orig' => '*Mar 1 18:48:50.483 UTC: %SYS-5-CONFIG_I: Configured from console by vty2 (10.34.195.36)', ]
];
$result[] = [ 'ios||23||5||5||26644:||2013-11-08 07:19:24|| 00:00:48: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet2/0/1, changed state to down 2 (Switch-2)||26644',
[ 'facility' => 'local7', 'priority' => '5', 'level' => '5',
'tag' => 'UPDOWN', 'program' => 'LINEPROTO',
'msg' => 'Line protocol on Interface GigabitEthernet2/0/1, changed state to down 2 (Switch-2)',
'msg_orig' => '00:00:48: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet2/0/1, changed state to down 2 (Switch-2)', ]
];
// Cisco IOS
$result[] = array('ios||23||5||5||26644:||2013-11-08 07:19:24|| *Mar 1 18:48:50.483 UTC: %SYS-5-CONFIG_I: Configured from console by vty2 (10.34.195.36)||26644',
array('facility' => 'local7', 'priority' => '5', 'level' => '5',
'tag' => 'CONFIG_I', 'program' => 'SYS',
'msg' => 'Configured from console by vty2 (10.34.195.36)',
'msg_orig' => '*Mar 1 18:48:50.483 UTC: %SYS-5-CONFIG_I: Configured from console by vty2 (10.34.195.36)',
));
$result[] = array('ios||23||5||5||26644:||2013-11-08 07:19:24|| 00:00:48: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet2/0/1, changed state to down 2 (Switch-2)||26644',
array('facility' => 'local7', 'priority' => '5', 'level' => '5',
'tag' => 'UPDOWN', 'program' => 'LINEPROTO',
'msg' => 'Line protocol on Interface GigabitEthernet2/0/1, changed state to down 2 (Switch-2)',
'msg_orig' => '00:00:48: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet2/0/1, changed state to down 2 (Switch-2)',
));
// Origin-ID
$result[] = [ 'ios||21||3||3||101:||2024-10-02 16:15:59|| 10.230.0.97: Oct 2 15:15:58: %LINK-3-UPDOWN: Interface GigabitEthernet1/0/7, changed state to up||101',
[ 'facility' => 'local5', 'priority' => '3', 'level' => '3',
'tag' => 'UPDOWN,10.230.0.97', 'program' => 'LINK',
'msg' => 'Interface GigabitEthernet1/0/7, changed state to up',
'msg_orig' => '10.230.0.97: Oct 2 15:15:58: %LINK-3-UPDOWN: Interface GigabitEthernet1/0/7, changed state to up', ]
];
$result[] = [ 'ios||21||5||5||119:||2024-10-02 16:17:51|| test-originid: Oct 2 15:17:50: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet1/0/7, changed state to up||119',
[ 'facility' => 'local5', 'priority' => '5', 'level' => '5',
'tag' => 'UPDOWN,test-originid', 'program' => 'LINEPROTO',
'msg' => 'Line protocol on Interface GigabitEthernet1/0/7, changed state to up',
'msg_orig' => 'test-originid: Oct 2 15:17:50: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet1/0/7, changed state to up', ]
];
// Unknown program and tag
$result[] = [ 'ios||23||7||7||12602:||2016-10-24 11:34:02|| Oct 24 11:34:01.275: VSTACK_ERR: ||12602',
[ 'facility' => 'local7', 'priority' => '7', 'level' => '7',
'tag' => 'debug', 'program' => 'DEBUG',
'msg' => 'VSTACK_ERR:',
'msg_orig' => 'Oct 24 11:34:01.275: VSTACK_ERR:', ]
];
$result[] = [ 'ios||23||7||7||12603:||2016-10-24 11:34:02|| smi_ibc_dl_handle_events : invalid message||12603',
[ 'facility' => 'local7', 'priority' => '7', 'level' => '7',
'tag' => 'debug', 'program' => 'DEBUG',
'msg' => 'smi_ibc_dl_handle_events : invalid message',
'msg_orig' => 'smi_ibc_dl_handle_events : invalid message', ]
];
$result[] = [ 'ios||23||7||7||12622:||2016-10-26 10:05:37|| Oct 26 10:05:36.301: Invalid packet (too small) length=0',
[ 'facility' => 'local7', 'priority' => '7', 'level' => '7',
'tag' => 'debug', 'program' => 'DEBUG',
'msg' => 'Invalid packet (too small) length=0',
'msg_orig' => 'Oct 26 10:05:36.301: Invalid packet (too small) length=0', ]
];
// Unknown program and tag
$result[] = array('ios||23||7||7||12602:||2016-10-24 11:34:02|| Oct 24 11:34:01.275: VSTACK_ERR: ||12602',
array('facility' => 'local7', 'priority' => '7', 'level' => '7',
'tag' => 'debug', 'program' => 'DEBUG',
'msg' => 'VSTACK_ERR:',
'msg_orig' => 'Oct 24 11:34:01.275: VSTACK_ERR:',
));
$result[] = array('ios||23||7||7||12603:||2016-10-24 11:34:02|| smi_ibc_dl_handle_events : invalid message||12603',
array('facility' => 'local7', 'priority' => '7', 'level' => '7',
'tag' => 'debug', 'program' => 'DEBUG',
'msg' => 'smi_ibc_dl_handle_events : invalid message',
'msg_orig' => 'smi_ibc_dl_handle_events : invalid message',
));
$result[] = array('ios||23||7||7||12622:||2016-10-26 10:05:37|| Oct 26 10:05:36.301: Invalid packet (too small) length=0',
array('facility' => 'local7', 'priority' => '7', 'level' => '7',
'tag' => 'debug', 'program' => 'DEBUG',
'msg' => 'Invalid packet (too small) length=0',
'msg_orig' => 'Oct 26 10:05:36.301: Invalid packet (too small) length=0',
));
// Examples from real system
$result[] = array('ios||23||4||4||26644:||2013-11-08 07:19:24|| 033884: Nov 8 07:19:23.993: %FW-4-TCP_OoO_SEG: Dropping TCP Segment: seq:-1169729434 1500 bytes is out-of-order; expected seq:3124765814. Reason: TCP reassembly queue overflow - session 10.10.32.37:56316 to 93.186.239.142:80 on zone-pair Local->Internet class All_Inspection||26644',
array('facility' => 'local7', 'priority' => '4', 'level' => '4',
'tag' => 'TCP_OoO_SEG', 'program' => 'FW',
'msg' => 'Dropping TCP Segment: seq:-1169729434 1500 bytes is out-of-order; expected seq:3124765814. Reason: TCP reassembly queue overflow - session 10.10.32.37:56316 to 93.186.239.142:80 on zone-pair Local->Internet class All_Inspection',
'msg_orig' => '033884: Nov 8 07:19:23.993: %FW-4-TCP_OoO_SEG: Dropping TCP Segment: seq:-1169729434 1500 bytes is out-of-order; expected seq:3124765814. Reason: TCP reassembly queue overflow - session 10.10.32.37:56316 to 93.186.239.142:80 on zone-pair Local->Internet class All_Inspection',
));
$result[] = array('ios||23||5||5||1747:||2018-03-12 13:47:44|| 001743: *Apr 25 04:16:54.749: %SSH-5-SSH2_SESSION: SSH2 Session request from 10.12.0.251 (tty = 0) using crypto cipher \'3des-cbc\', hmac \'hmac-md5\' Succeeded||1747',
array('facility' => 'local7', 'priority' => '5', 'level' => '5',
'tag' => 'SSH2_SESSION', 'program' => 'SSH',
'msg' => 'SSH2 Session request from 10.12.0.251 (tty = 0) using crypto cipher \'3des-cbc\', hmac \'hmac-md5\' Succeeded',
'msg_orig' => '001743: *Apr 25 04:16:54.749: %SSH-5-SSH2_SESSION: SSH2 Session request from 10.12.0.251 (tty = 0) using crypto cipher \'3des-cbc\', hmac \'hmac-md5\' Succeeded',
));
$result[] = array('ios||23||5||5||908:||2018-03-12 13:45:15|| Mar 12 13:45:14.241: %SSH-5-SSH2_SESSION: SSH2 Session request from 10.10.10.10 (tty = 0) using crypto cipher \'3des-cbc\', hmac \'hmac-md5\' Succeeded||908',
array('facility' => 'local7', 'priority' => '5', 'level' => '5',
'tag' => 'SSH2_SESSION', 'program' => 'SSH',
'msg' => 'SSH2 Session request from 10.10.10.10 (tty = 0) using crypto cipher \'3des-cbc\', hmac \'hmac-md5\' Succeeded',
'msg_orig' => 'Mar 12 13:45:14.241: %SSH-5-SSH2_SESSION: SSH2 Session request from 10.10.10.10 (tty = 0) using crypto cipher \'3des-cbc\', hmac \'hmac-md5\' Succeeded',
));
$result[] = array('ios||23||5||5||2559:||2017-01-26 04:27:10|| 003174: Jan 26 04:27:09.174 MSK: %BGP-5-ADJCHANGE: neighbor 10.0.1.17 vpn vrf hostcomm-private Up ||2559',
array('facility' => 'local7', 'priority' => '5', 'level' => '5',
'tag' => 'ADJCHANGE', 'program' => 'BGP',
'msg' => 'neighbor 10.0.1.17 vpn vrf hostcomm-private Up',
'msg_orig' => '003174: Jan 26 04:27:09.174 MSK: %BGP-5-ADJCHANGE: neighbor 10.0.1.17 vpn vrf hostcomm-private Up',
));
$result[] = array('ios||23||4||4||12601:||2016-10-24 11:34:01|| -Traceback= BF7490z 195628z 10D3A0Cz 10D30B8z 10D8C28z 10D9B70z 10DAFE0z 10DB174z 10D34ECz 133F918z 133A9D4z||12601',
array('facility' => 'local7', 'priority' => '4', 'level' => '4',
'tag' => 'Traceback', 'program' => 'TRACEBACK',
'msg' => 'BF7490z 195628z 10D3A0Cz 10D30B8z 10D8C28z 10D9B70z 10DAFE0z 10DB174z 10D34ECz 133F918z 133A9D4z',
'msg_orig' => '-Traceback= BF7490z 195628z 10D3A0Cz 10D30B8z 10D8C28z 10D9B70z 10DAFE0z 10DB174z 10D34ECz 133F918z 133A9D4z',
));
// Examples from real system
$result[] = [ 'ios||23||4||4||26644:||2013-11-08 07:19:24|| 033884: Nov 8 07:19:23.993: %FW-4-TCP_OoO_SEG: Dropping TCP Segment: seq:-1169729434 1500 bytes is out-of-order; expected seq:3124765814. Reason: TCP reassembly queue overflow - session 10.10.32.37:56316 to 93.186.239.142:80 on zone-pair Local->Internet class All_Inspection||26644',
[ 'facility' => 'local7', 'priority' => '4', 'level' => '4',
'tag' => 'TCP_OoO_SEG', 'program' => 'FW',
'msg' => 'Dropping TCP Segment: seq:-1169729434 1500 bytes is out-of-order; expected seq:3124765814. Reason: TCP reassembly queue overflow - session 10.10.32.37:56316 to 93.186.239.142:80 on zone-pair Local->Internet class All_Inspection',
'msg_orig' => '033884: Nov 8 07:19:23.993: %FW-4-TCP_OoO_SEG: Dropping TCP Segment: seq:-1169729434 1500 bytes is out-of-order; expected seq:3124765814. Reason: TCP reassembly queue overflow - session 10.10.32.37:56316 to 93.186.239.142:80 on zone-pair Local->Internet class All_Inspection', ]
];
$result[] = [ 'ios||23||5||5||1747:||2018-03-12 13:47:44|| 001743: *Apr 25 04:16:54.749: %SSH-5-SSH2_SESSION: SSH2 Session request from 10.12.0.251 (tty = 0) using crypto cipher \'3des-cbc\', hmac \'hmac-md5\' Succeeded||1747',
[ 'facility' => 'local7', 'priority' => '5', 'level' => '5',
'tag' => 'SSH2_SESSION', 'program' => 'SSH',
'msg' => 'SSH2 Session request from 10.12.0.251 (tty = 0) using crypto cipher \'3des-cbc\', hmac \'hmac-md5\' Succeeded',
'msg_orig' => '001743: *Apr 25 04:16:54.749: %SSH-5-SSH2_SESSION: SSH2 Session request from 10.12.0.251 (tty = 0) using crypto cipher \'3des-cbc\', hmac \'hmac-md5\' Succeeded', ]
];
$result[] = [ 'ios||23||5||5||908:||2018-03-12 13:45:15|| Mar 12 13:45:14.241: %SSH-5-SSH2_SESSION: SSH2 Session request from 10.10.10.10 (tty = 0) using crypto cipher \'3des-cbc\', hmac \'hmac-md5\' Succeeded||908',
[ 'facility' => 'local7', 'priority' => '5', 'level' => '5',
'tag' => 'SSH2_SESSION', 'program' => 'SSH',
'msg' => 'SSH2 Session request from 10.10.10.10 (tty = 0) using crypto cipher \'3des-cbc\', hmac \'hmac-md5\' Succeeded',
'msg_orig' => 'Mar 12 13:45:14.241: %SSH-5-SSH2_SESSION: SSH2 Session request from 10.10.10.10 (tty = 0) using crypto cipher \'3des-cbc\', hmac \'hmac-md5\' Succeeded', ]
];
$result[] = [ 'ios||23||5||5||2559:||2017-01-26 04:27:10|| 003174: Jan 26 04:27:09.174 MSK: %BGP-5-ADJCHANGE: neighbor 10.0.1.17 vpn vrf hostcomm-private Up ||2559',
[ 'facility' => 'local7', 'priority' => '5', 'level' => '5',
'tag' => 'ADJCHANGE', 'program' => 'BGP',
'msg' => 'neighbor 10.0.1.17 vpn vrf hostcomm-private Up',
'msg_orig' => '003174: Jan 26 04:27:09.174 MSK: %BGP-5-ADJCHANGE: neighbor 10.0.1.17 vpn vrf hostcomm-private Up', ]
];
$result[] = [ 'ios||23||4||4||12601:||2016-10-24 11:34:01|| -Traceback= BF7490z 195628z 10D3A0Cz 10D30B8z 10D8C28z 10D9B70z 10DAFE0z 10DB174z 10D34ECz 133F918z 133A9D4z||12601',
[ 'facility' => 'local7', 'priority' => '4', 'level' => '4',
'tag' => 'Traceback', 'program' => 'TRACEBACK',
'msg' => 'BF7490z 195628z 10D3A0Cz 10D30B8z 10D8C28z 10D9B70z 10DAFE0z 10DB174z 10D34ECz 133F918z 133A9D4z',
'msg_orig' => '-Traceback= BF7490z 195628z 10D3A0Cz 10D30B8z 10D8C28z 10D9B70z 10DAFE0z 10DB174z 10D34ECz 133F918z 133A9D4z', ]
];
// Cisco IOS-XR
@ -346,12 +360,35 @@ class IncludesSyslogTest extends \PHPUnit\Framework\TestCase {
'msg' => '[420813.870000] wmi_unified_event_rx : no registered event handler : event id 0x901b',
'msg_orig' => 'kernel: [420813.870000] wmi_unified_event_rx : no registered event handler : event id 0x901b',
));
$result[] = array('unifi||1||6||6||U7LR,44d9e7f618f2,v4.3.21.11325:||2020-10-05 16:28:50|| : stahtd[2839]: [STA-TRACKER].stahtd_dump_event(): {"mac":"0c:70:4a:7d:5c:73","message_type":"STA_ASSOC_TRACKER","vap":"ath4","auth_ts":"0.0","event_type":"fixup","event_id":"1","assoc_status":"0","arp_reply_gw_seen":"yes","dns_resp_seen":"yes"}||U7LR,44d9e7f618f2,v4.3.21.11325',
array('facility' => 'user', 'priority' => '6', 'level' => '6',
'tag' => 'stahtd[2839]', 'program' => 'STAHTD',
'msg' => '[STA-TRACKER].stahtd_dump_event(): {"mac":"0c:70:4a:7d:5c:73","message_type":"STA_ASSOC_TRACKER","vap":"ath4","auth_ts":"0.0","event_type":"fixup","event_id":"1","assoc_status":"0","arp_reply_gw_seen":"yes","dns_resp_seen":"yes"}',
'msg_orig' => ': stahtd[2839]: [STA-TRACKER].stahtd_dump_event(): {"mac":"0c:70:4a:7d:5c:73","message_type":"STA_ASSOC_TRACKER","vap":"ath4","auth_ts":"0.0","event_type":"fixup","event_id":"1","assoc_status":"0","arp_reply_gw_seen":"yes","dns_resp_seen":"yes"}',
));
$result[] = [ 'unifi||1||6||6||U7LR,44d9e7f618f2,v4.3.21.11325:||2020-10-05 16:28:50|| : stahtd[2839]: [STA-TRACKER].stahtd_dump_event(): {"mac":"0c:70:4a:7d:5c:73","message_type":"STA_ASSOC_TRACKER","vap":"ath4","auth_ts":"0.0","event_type":"fixup","event_id":"1","assoc_status":"0","arp_reply_gw_seen":"yes","dns_resp_seen":"yes"}||U7LR,44d9e7f618f2,v4.3.21.11325',
[ 'facility' => 'user', 'priority' => '6', 'level' => '6',
'tag' => 'stahtd[2839]', 'program' => 'STAHTD',
'msg' => '[STA-TRACKER].stahtd_dump_event(): {"mac":"0c:70:4a:7d:5c:73","message_type":"STA_ASSOC_TRACKER","vap":"ath4","auth_ts":"0.0","event_type":"fixup","event_id":"1","assoc_status":"0","arp_reply_gw_seen":"yes","dns_resp_seen":"yes"}',
'msg_orig' => ': stahtd[2839]: [STA-TRACKER].stahtd_dump_event(): {"mac":"0c:70:4a:7d:5c:73","message_type":"STA_ASSOC_TRACKER","vap":"ath4","auth_ts":"0.0","event_type":"fixup","event_id":"1","assoc_status":"0","arp_reply_gw_seen":"yes","dns_resp_seen":"yes"}',
] ];
// Unifi v2 new format... fuck you Ubiquiti with your changes in each firmware!
$result[] = [ 'unifi||0||4||4||44d9e7f618f2,UAP-AC-LR-6.5.28+14491:||2023-03-06 15:57:43|| kernel: [399142.041095] [wifi1] FWLOG: [6086408] WAL_DBGID_SECURITY_MCAST_KEY_SET ( 0x2 )||44d9e7f618f2,UAP-AC-LR-6.5.28+14491',
[ 'facility' => 'kern', 'priority' => '4', 'level' => '4',
'tag' => 'kernel', 'program' => 'KERNEL',
'msg' => '[399142.041095] [wifi1] FWLOG: [6086408] WAL_DBGID_SECURITY_MCAST_KEY_SET ( 0x2 )',
'msg_orig' => 'kernel: [399142.041095] [wifi1] FWLOG: [6086408] WAL_DBGID_SECURITY_MCAST_KEY_SET ( 0x2 )',
] ];
$result[] = [ 'unifi||3||6||6||44d9e7f618f2,UAP-AC-LR-6.5.28+14491:||2023-03-06 15:43:20|| hostapd[15580]: ath4: STA d4:57:63:d6:a0:c3 IEEE 802.11: sta_stats||44d9e7f618f2,UAP-AC-LR-6.5.28+14491',
[ 'facility' => 'daemon', 'priority' => '6', 'level' => '6',
'tag' => 'hostapd[15580]', 'program' => 'HOSTAPD',
'msg' => 'ath4: STA d4:57:63:d6:a0:c3 IEEE 802.11: sta_stats',
'msg_orig' => 'hostapd[15580]: ath4: STA d4:57:63:d6:a0:c3 IEEE 802.11: sta_stats',
] ];
$result[] = [ 'unifi||3||6||6||44d9e7f618f2,UAP-AC-LR-6.5.28+14491:||2023-03-06 15:43:20|| stahtd: stahtd[15573]: [STA-TRACKER].stahtd_dump_event(): {"message_type":"STA_ASSOC_TRACKER","mac":"d4:57:63:d6:a0:c3","vap":"ath4","event_type":"sta_roam","assoc_status":"0","event_id":"1"}||44d9e7f618f2,UAP-AC-LR-6.5.28+14491',
[ 'facility' => 'daemon', 'priority' => '6', 'level' => '6',
'tag' => 'stahtd', 'program' => 'STAHTD',
'msg' => '[STA-TRACKER].stahtd_dump_event(): {"message_type":"STA_ASSOC_TRACKER","mac":"d4:57:63:d6:a0:c3","vap":"ath4","event_type":"sta_roam","assoc_status":"0","event_id":"1"}',
'msg_orig' => 'stahtd: stahtd[15573]: [STA-TRACKER].stahtd_dump_event(): {"message_type":"STA_ASSOC_TRACKER","mac":"d4:57:63:d6:a0:c3","vap":"ath4","event_type":"sta_roam","assoc_status":"0","event_id":"1"}',
] ];
// JunOS/JunOSe
$result[] = array('junos||9||6||6||/usr/sbin/cron[50991]:||2016-10-07 00:15:00|| (root) CMD ( /usr/libexec/atrun)||',
@ -476,6 +513,40 @@ class IncludesSyslogTest extends \PHPUnit\Framework\TestCase {
'msg_orig' => 'Member port XGE1/0/33 of aggregation group BAGG33 changed to the inactive state, because the physical state of the port is down.',
));
// ArubaOS
$result[] = [ 'arubaos||1||6||6||00413||2023-10-11 17:37:28|| SNTP: Updated time by 4 seconds from server at 192.129.28.2. Previous time was Wed Oct 11 17:37:24 2023. Current time is Wed Oct 11 17:37:28 2023.||00413',
[ 'facility' => 'user', 'priority' => '6', 'level' => '6',
'tag' => '00413', 'program' => 'SNTP',
'msg' => 'Updated time by 4 seconds from server at 192.129.28.2. Previous time was Wed Oct 11 17:37:24 2023. Current time is Wed Oct 11 17:37:28 2023.',
'msg_orig' => 'SNTP: Updated time by 4 seconds from server at 192.129.28.2. Previous time was Wed Oct 11 17:37:24 2023. Current time is Wed Oct 11 17:37:28 2023.', ]
];
$result[] = [ 'arubaos||1||6||6||00076||2023-10-11 16:13:18|| ports: port 38 is now on-line||00076',
[ 'facility' => 'user', 'priority' => '6', 'level' => '6',
'tag' => '00076', 'program' => 'PORTS',
'msg' => 'port 38 is now on-line',
'msg_orig' => 'ports: port 38 is now on-line', ]
];
// ArubaOS-CX
$result[] = [ 'arubaos-cx||23||6||6||log-proxyd[2872]||2023-10-06 13:50:24||Event|5209|LOG_INFO|AMM|1/5|User !raabc logged in from 10.30.2.245 through SSH session.||log-proxyd',
[ 'facility' => 'local7', 'priority' => '6', 'level' => '6',
'tag' => '5209,AMM,1/5', 'program' => 'LOG-PROXYD',
'msg' => 'User !raabc logged in from 10.30.2.245 through SSH session.',
'msg_orig' => 'Event|5209|LOG_INFO|AMM|1/5|User !raabc logged in from 10.30.2.245 through SSH session.', ]
];
$result[] = [ 'arubaos-cx||23||6||6||lacpd[3920]||2023-02-23 12:26:49||Event|1307|LOG_INFO|UMM|-|LACP system ID set to 08:f1:ea:61:2a:00||lacpd',
[ 'facility' => 'local7', 'priority' => '6', 'level' => '6',
'tag' => '1307,UMM', 'program' => 'LACPD',
'msg' => 'LACP system ID set to 08:f1:ea:61:2a:00',
'msg_orig' => 'Event|1307|LOG_INFO|UMM|-|LACP system ID set to 08:f1:ea:61:2a:00', ]
];
$result[] = [ 'arubaos-cx||23||2||2||crash-tools[3920]||2023-02-23 12:26:49||Event|1206|LOG_CRIT|||Module rebooted. Reason : Reboot requested by user, Version: XL.10.10.1020#012, Boot-ID : fed7f6e9e75f4d95a4fb3b4643f024d5||crash-tools',
[ 'facility' => 'local7', 'priority' => '2', 'level' => '2',
'tag' => '1206', 'program' => 'CRASH-TOOLS',
'msg' => 'Module rebooted. Reason : Reboot requested by user, Version: XL.10.10.1020#012, Boot-ID : fed7f6e9e75f4d95a4fb3b4643f024d5',
'msg_orig' => 'Event|1206|LOG_CRIT|||Module rebooted. Reason : Reboot requested by user, Version: XL.10.10.1020#012, Boot-ID : fed7f6e9e75f4d95a4fb3b4643f024d5', ]
];
// NS-BSD
$result[] = array('ns-bsd||user||5||notice||0d||2018-10-16 18:13:05||2018-10-16T18:13:03+02:00 fw.hostname.net tproxyd - - - id=firewall time=\"2018-10-16 18:13:03\" fw=\"fw.hostname.net\" tz=+0200 startime=\"2018-10-16 18:13:02\" pri=5 proto=http confid=1 slotlevel=2 ruleid=9 rulename=\"16663e6700f_5\" op=GET result=416 user=\"\" domain=\"\" src=192.168.0.148 srcport=59365 srcportname=ephemeral_fw_tcp dst=88.221.145.155 dstport=80 dstportname=http srcmac=54:27:1e:5c:22:bb dstname=2.tlu.dl.delivery.mp.microsoft.com modsrc=192.168.1.2 modsrcport=9619 origdst=88.221.145.155 origdstport=80 ipv=4 sent=484 rcvd=0 duration=0.00 dstcontinent=\"eu\" dstcountry=\"it\" action=block contentpolicy=1 urlruleid=2 cat_site=\"vpnssl_owa\" arg=\"/filestreamingservice/files/5fa99684-8931-4eff-bc5d-27ff2a406a31%3FP1%3D1539706618%26P2%3D402%26P3%3D2%26P4%3DHCvXZchoZYgzbdK0XkO2CelafFHcA%252bUrQcgT5u%252b6WDwtpi5jZJu%252fUjCHpbffRGU5iG8kuHW1C5uQ68drtUWh%252fA%253d%253d\" msg=\"Requested range not satisfiable\" logtype=\"web\"||1',
array('facility' => 'user', 'priority' => '5', 'level' => '5',

View File

@ -6,9 +6,13 @@ $config['install_dir'] = $base_dir;
// Base observium includes
include(__DIR__ . '/../includes/defaults.inc.php');
//include(dirname(__FILE__) . '/../config.php'); // Do not include user editable config here
include(__DIR__ . "/../includes/polyfill.inc.php");
include(__DIR__ . "/../includes/autoloader.inc.php");
include(__DIR__ . "/../includes/debugging.inc.php");
require_once(__DIR__ ."/../includes/constants.inc.php");
include(__DIR__ . '/../includes/common.inc.php');
include(__DIR__ . '/../includes/definitions.inc.php');
//include(dirname(__FILE__) . '/data/test_definitions.inc.php'); // Fake definitions for testing
//include(__DIR__ . '/data/test_definitions.inc.php'); // Fake definitions for testing
include(__DIR__ . '/../includes/functions.inc.php');
class IncludesTemplatesTest extends \PHPUnit\Framework\TestCase

View File

@ -4,7 +4,7 @@
define('OBS_QUIET', TRUE); // Disable any additional output from tests
ini_set('opcache.enable', 0);
include(__DIR__ . '/../includes/sql-config.inc.php');
include(__DIR__ . '/../includes/observium.inc.php');
//include(dirname(__FILE__) . '/../includes/defaults.inc.php');
//include(dirname(__FILE__) . '/../config.php');
//include(dirname(__FILE__) . '/../includes/definitions.inc.php');
@ -25,8 +25,8 @@ include(__DIR__ . '/../includes/sql-config.inc.php');
*/
// SNMPsim tests
$snmpsimd_ip = $config['tests']['snmpsim_ip'] ?: '127.0.0.1';
$snmpsimd_port = $config['tests']['snmpsim_port'] ?: 16111;
$snmpsimd_ip = $config['tests']['snmpsim_ip'] ?? '127.0.0.1';
$snmpsimd_port = $config['tests']['snmpsim_port'] ?? 16111;
$snmpsimd_data = $config['tests']['snmpsim_dir'] . '/os';
if (is_dir($snmpsimd_data)) {
snmpsimd_init($snmpsimd_data);
@ -275,15 +275,62 @@ class SnmpDataTest extends \PHPUnit\Framework\TestCase
if ($result)
{
// good response - int greater than 0
$this->assertGreaterThan(0, isSNMPable($device));
$this->assertGreaterThan(0, is_snmpable($device));
} else {
// bad response return 0
$device['snmp_timeout'] = 1;
$this->assertSame(0, isSNMPable($device));
$this->assertSame(0, is_snmpable($device));
}
}
}
/**
* @dataProvider providerIsSNMPable
* @group snmperrors
*/
public function testIsSNMPableError($os, $test_os, $status, $error = OBS_SNMP_ERROR_OK)
{
global $snmpsimd_ip, $snmpsimd_port;
$GLOBALS['config']['snmp']['errors'] = FALSE; // force disable log to db
foreach ([ 'v2c', 'v3' ] as $snmp_version)
//foreach (array('v3') as $snmp_version)
{
switch ($snmp_version)
{
case 'v2c':
$community = $os . '-1';
$device = build_initial_device_array($snmpsimd_ip, $community, $snmp_version, $snmpsimd_port, 'udp');
break;
case 'v3':
$snmp_version = 'v3';
$snmp_v3 = [ 'authlevel' => 'authPriv',
'authname' => 'simulator',
'authpass' => 'auctoritas',
'authalgo' => 'MD5',
'cryptopass' => 'privatus',
'cryptoalgo' => 'DES' ];
$device = build_initial_device_array($snmpsimd_ip, NULL, $snmp_version, $snmpsimd_port, 'udp', $snmp_v3);
$device['snmp_context'] = $os . '-1';
break;
}
$device['snmp_timeout'] = 2;
$device['snmp_retries'] = 1;
//var_dump($device);
if ($test_os)
{
$device['os'] = $test_os;
}
if (!$status) {
// bad response return 0
$device['snmp_timeout'] = 1;
}
is_snmpable($device);
$this->assertSame($error, snmp_error_code());
}
}
public function providerIsSNMPable()
{
return array(
@ -308,9 +355,9 @@ class SnmpDataTest extends \PHPUnit\Framework\TestCase
array('hikvision-cam', '8734hr7hf3f38', TRUE), // simulate os name changed
// Simulate not snmpable device
array('hikvision-XXX', NULL, FALSE), // os not known
array('hikvision-XXX', 'hikvision-cam', FALSE), // known os
array('hikvision-XXX', '8734hr7hf3f38', FALSE), // simulate os name changed
array('hikvision-XXX', NULL, FALSE, OBS_SNMP_ERROR_REQUEST_TIMEOUT), // os not known
array('hikvision-XXX', 'hikvision-cam', FALSE, OBS_SNMP_ERROR_ISSNMPABLE), // known os
array('hikvision-XXX', '8734hr7hf3f38', FALSE, OBS_SNMP_ERROR_REQUEST_TIMEOUT), // simulate os name changed
);
}
}

View File

@ -4,7 +4,7 @@
//define('OBS_QUIET', TRUE); // Disable any additional output from tests
ini_set('opcache.enable', 0);
include(dirname(__FILE__) . '/../includes/sql-config.inc.php');
include(__DIR__ . '/../includes/observium.inc.php');
//include(dirname(__FILE__) . '/../includes/defaults.inc.php');
//include(dirname(__FILE__) . '/../config.php');
//include(dirname(__FILE__) . '/../includes/definitions.inc.php');
@ -25,8 +25,8 @@ include(dirname(__FILE__) . '/../includes/sql-config.inc.php');
*/
// SNMPsim tests
$snmpsimd_ip = isset($config['tests']['snmpsim_ip']) ? $config['tests']['snmpsim_ip'] : '127.0.0.1';
$snmpsimd_port = isset($config['tests']['snmpsim_port']) ? $config['tests']['snmpsim_port'] : 16111;
$snmpsimd_ip = $config['tests']['snmpsim_ip'] ?? '127.0.0.1';
$snmpsimd_port = $config['tests']['snmpsim_port'] ?? 16111;
$snmpsimd_data = $config['tests']['snmpsim_dir'] . '/full';
if (is_dir($snmpsimd_data))
{

View File

@ -7,7 +7,7 @@
*
* @package observium
* @subpackage tests
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
* @copyright (C) Adam Armstrong
*
*/
@ -20,7 +20,7 @@
$GLOBALS['cache']['db_version'] = 999; // Set fake DB version
setlocale(LC_ALL, 'C');
putenv('LC_ALL=C');
define('OBS_DEBUG', 0);
if (!defined('OBS_DEBUG')) { define('OBS_DEBUG', 0); }
/*
set_include_path(dirname(__FILE__) . "/../../includes/pear" . PATH_SEPARATOR . get_include_path());
@ -36,6 +36,8 @@ $config['os_group']['default']['graphs'][] = "device_bits";
$config['os_group']['default']['graphs'][] = "device_uptime";
$config['os_group']['default']['graphs'][] = "device_ping";
$config['os_group']['default']['comments'] = "/^\s*#/";
$config['os_group']['default']['modules']['unix-agent'] = 0; // unix agent enabled by default only for unix group
$config['os_group']['default']['modules']['applications'] = 0;
// MIBs enabled for any os (except blacklisted mibs)
$config['os_group']['default']['mibs'][] = "EtherLike-MIB"; // in ports module
$config['os_group']['default']['mibs'][] = "ENTITY-MIB";
@ -48,6 +50,7 @@ $config['os_group']['default']['mibs'][] = "CISCO-CDP-MIB";
$config['os_group']['default']['mibs'][] = "PW-STD-MIB"; // Pseudowires. FIXME, possible more os specific?
$config['os_group']['default']['mibs'][] = "DISMAN-PING-MIB";// RFC4560, SLA
$config['os_group']['default']['mibs'][] = "BGP4-MIB";
$config['os_group']['default']['vendortype_mib'] = "CISCO-ENTITY-VENDORTYPE-OID-MIB";
$os_group = "test_unix";
$config['os_group'][$os_group]['type'] = "server";

View File

@ -5,7 +5,7 @@
*
* @package observium
* @subpackage templates
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2023 Observium Limited
*
*/
/**