-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix #80661: Add string output format function for SNMP #6633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
29cebb7
6ceacb3
894521a
6c455fa
1be056a
3863954
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ function snmp_set_enum_print(bool $enable): bool {} | |
|
||
function snmp_set_oid_output_format(int $format): bool {} | ||
|
||
function snmp_set_string_output_format(int $format): bool {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, now I at least see why you picked the bool return value... I would still go for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Taking your word for it, I'm the old new guy ;) |
||
|
||
/** @alias snmp_set_oid_output_format */ | ||
function snmp_set_oid_numeric_print(int $format): bool {} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,33 @@ | ||
<?php | ||
|
||
/* | ||
By default tests will try to access SNMP agent @ '127.0.0.1:161' and will use 'public' community for read | ||
requests and 'private' community for write requests. | ||
Default timeout is 1000ms and there will be one request performed. | ||
*/ | ||
/** | ||
* By default tests will try to access SNMP agent @ '127.0.0.1:161' | ||
* and will use 'public' community for read requests | ||
* and will use 'private' community for write requests. | ||
* Default timeout is 1000ms and there will be one request performed. | ||
*/ | ||
|
||
$hostname4 = getenv('SNMP_HOSTNAME') ?: '127.0.0.1'; | ||
$hostname6 = getenv('SNMP_HOSTNAME6') ?: '::1'; | ||
$port = getenv('SNMP_PORT') ?: '161'; | ||
$hostname = "$hostname4:$port"; | ||
$hostname4 = getenv('SNMP_HOSTNAME') ?: '127.0.0.1'; | ||
$hostname6 = getenv('SNMP_HOSTNAME6') ?: '::1'; | ||
$port = getenv('SNMP_PORT') ?: '161'; | ||
|
||
$hostname = "$hostname4:$port"; | ||
$hostname6_port = "[$hostname6]:$port"; | ||
$community = getenv('SNMP_COMMUNITY') ?: 'public'; | ||
$communityWrite = getenv('SNMP_COMMUNITY_WRITE')?:'private'; | ||
|
||
$timeout = getenv('SNMP_TIMEOUT') ?: -1; | ||
$retries = getenv('SNMP_RETRIES') ?: 1; | ||
$community = getenv('SNMP_COMMUNITY') ?: 'public'; | ||
$communityWrite = getenv('SNMP_COMMUNITY_WRITE') ?: 'private'; | ||
|
||
$timeout = getenv('SNMP_TIMEOUT') ?: -1; | ||
$retries = getenv('SNMP_RETRIES') ?: 1; | ||
|
||
if (stristr(PHP_OS, "FreeBSD")) { | ||
$mibdir = getenv('SNMP_MIBDIR') ?: "/usr/local/share/snmp/mibs"; | ||
if (stristr(PHP_OS, 'FreeBSD')) { | ||
$mibdir = getenv('SNMP_MIBDIR') ?: '/usr/local/share/snmp/mibs'; | ||
} else { | ||
$mibdir = getenv('SNMP_MIBDIR') ?: "/usr/share/snmp/mibs"; | ||
$mibdir = getenv('SNMP_MIBDIR') ?: '/usr/share/snmp/mibs'; | ||
} | ||
|
||
|
||
$user_noauth = getenv('SNMP_USER_NOAUTH') ?: 'noAuthUser'; | ||
$user_auth_prefix = getenv('SNMP_USER_PREFIX') ?: 'admin'; | ||
$rwuser = getenv('SNMP_RWUSER') ?: ($user_auth_prefix . 'MD5AES'); | ||
$auth_pass = getenv('SNMP_AUTH_PASS') ?: 'test1234'; | ||
$priv_pass = getenv('SNMP_PRIV_PASS') ?: 'test1234'; | ||
$user_noauth = getenv('SNMP_USER_NOAUTH') ?: 'noAuthUser'; | ||
$user_auth_prefix = getenv('SNMP_USER_PREFIX') ?: 'admin'; | ||
$rwuser = getenv('SNMP_RWUSER') ?: ($user_auth_prefix . 'MD5AES'); | ||
$auth_pass = getenv('SNMP_AUTH_PASS') ?: 'test1234'; | ||
$priv_pass = getenv('SNMP_PRIV_PASS') ?: 'test1234'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--TEST-- | ||
Function snmp_set_string_output_format | ||
--SKIPIF-- | ||
<?php | ||
require_once(__DIR__.'/skipif.inc'); | ||
if (!function_exists('snmp_set_string_output_format')) die('skip This function is only available if using NET_SNMP'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I can tell, a separate check for the function is not needed here, just the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I said before, I copied whole cloth from a similar function. Give it some thought as making that decision here should/will impact others as well. |
||
?> | ||
--FILE-- | ||
<?php | ||
require_once(__DIR__.'/snmp_include.inc'); | ||
|
||
echo "Checking error handling\n"; | ||
try { | ||
var_dump(snmp_set_string_output_format(123)); | ||
} catch (\ValueError $e) { | ||
echo $e->getMessage() . \PHP_EOL; | ||
} | ||
|
||
echo "Checking working\n"; | ||
var_dump(snmp_set_string_output_format(SNMP_STRING_OUTPUT_GUESS)); | ||
var_dump(snmp_set_string_output_format(SNMP_STRING_OUTPUT_ASCII)); | ||
var_dump(snmp_set_string_output_format(SNMP_STRING_OUTPUT_HEX)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also fetch something here to see that the output format actually has some effect. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, the trick is, it'll be different on each system. I'll guess we can request that the sysLocation be set in the snmpd.conf and that way it'll always succeed. Add that to the test configuration. |
||
?> | ||
--EXPECT-- | ||
Checking error handling | ||
snmp_set_string_output_format(): Argument #1 ($format) must be an SNMP_STRING_OUTPUT_* constant | ||
Checking working | ||
bool(true) | ||
bool(true) | ||
bool(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This return value doesn't make much sense to me. I think it would be better to make this a void function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment about
snmp_set_oid_value_format()
above.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, shall we also modify the snmp_set_oid_value_format()?