Это net-snmp в ARM Linux, вызывающий программу C# с использованием файла pass_persist. Мой snmpd.conf выглядит так:
agentAddress udp:161
engineIDType 3
syslocation "My Location"
syscontact "root@unknown"
rocommunity public
rwcommunity private
view all included .1.3.6.1.4.1.12345
pass_persist .1.3.6.1.4.1.12345.999.1 /usr/share/test/TestSnmpResponder
Я также пробовал со следующей строкой:
pass_persist .1.3.6.1.4.1.12345 /usr/share/test/TestSnmpResponder
Ответчик отлично работает в командной строке (отправка PING
приводит к PONG
, и отвечает на все запросы фиксированным целым числом просто в качестве теста.
Когда я запускаю демон net-snmp, я получаю в журнале следующее:
/etc/snmp/snmpd.conf: line 12: Warning: Unknown token: pass_persist.
NET-SNMP version 5.9
Затем он нормально отвечает на запросы SNMP, но не вызывает и не загружает программу pass_persist. Я получаю ту же ошибку, если заменяю pass_persist
на pass
просто в качестве теста.
Просто для полноты кода С#:
internal class Program
{
static void Main(string[] args)
{
File.AppendAllText("log.txt", $"Started daemon");
using (var inputStream = Console.OpenStandardInput())
using (var strStream = new StreamReader(inputStream))
{
while (true)
{
var command = strStream.ReadLine()!;
switch (command.ToUpper())
{
case "":
//Tells the system to stop and quit
Environment.ExitCode = 0;
Environment.Exit(0);
break;
case "PING":
Console.WriteLine("PONG");
break;
case "GET":
string oid = strStream.ReadLine()!;
File.AppendAllText("log.txt", $"GET {oid}");
Console.WriteLine("integer");
Console.WriteLine("998877");
break;
case "GETNEXT":
case "SET":
default:
break;
}
}
}
}
}
Я пропустил какую-то конфигурацию в конфигурации net-snmp во время сборки?
Так что, видимо, это была проблема с конфигурацией Buildroot по умолчанию. Чтобы диагностировать проблему, я выполнил следующую команду:
snmpd -Dmib_init -H
Что привело к следующему выводу «понятных» директив:
Configuration directives understood: In snmpd.conf and snmpd.local.conf:
authtrapenable 1 | 2 (1 = enable, 2 = disable)
trapsink [-profile p] [-name n] [-tag t] host [community] [port]
trap2sink [-profile p] [-name n] [-tag t] host [community] [port]
informsink [-profile p] [-name n] [-tag t] host [community] [port]
trapsess [-profile p] [-name n] [-tag t] [snmpcmdargs] host
trapcommunity community-string
v1trapaddress string
agentuser userid
agentgroup groupid
agentaddress SNMP bind address
quit (1|yes|true|0|no|false)
leave_pidfile (1|yes|true|0|no|false)
dontLogTCPWrappersConnects (1|yes|true|0|no|false)
maxGetbulkRepeats integerValue
maxGetbulkResponses integerValue
avgBulkVarbindSize integerValue
pduStatsMax integerValue
pduStatsThreshold integerValue
injectHandler injectHandler NAME INTONAME [BEFORE_OTHER_NAME]
table tableoid
add_row table_name indexes... values...
agentxsocket AgentX bind address
agentxRetries AgentX Retries
agentxTimeout AgentX Timeout (seconds)
master specify 'agentx' for AgentX support
agentxperms AgentX socket permissions: socket_perms [directory_perms [username|userid [groupname|groupid]]]
com2sec [-Cn CONTEXT] secName IPv4-network-address[/netmask] community
com2sec6 [-Cn CONTEXT] secName IPv6-network-address[/netmask] community
com2secunix [-Cn CONTEXT] secName sockpath community
certSecName certSecName PRIORITY FINGERPRINT [--shaNN|md5] <--sn SECNAME | --rfc822 | --dns | --ip | --cn | --any>
snmpTlstmParams snmpTlstmParams targetParamsName hashType:fingerPrint
snmpTlstmAddr snmpTlstmAddr targetAddrName hashType:fingerprint serverIdentity
group name v1|v2c|usm|... security
access name context model level prefix read write notify
setaccess name context model level prefix viewname viewval
view name type subtree [mask]
authcommunity authtype1,authtype2 community [default|hostname|network/bits [oid|-V view [context]]]
authuser authtype1,authtype2 [-s secmodel] user [noauth|auth|priv [oid|-V view [context]]]
authgroup authtype1,authtype2 [-s secmodel] group [noauth|auth|priv [oid|-V view [context]]]
authaccess name authtype1,authtype2 [-s secmodel] group view [noauth|auth|priv [context|context*]]
rwcommunity community [default|hostname|network/bits [oid|-V view [context]]]
rocommunity community [default|hostname|network/bits [oid|-V view [context]]]
rwcommunity6 community [default|hostname|network/bits [oid|-V view [context]]]
rocommunity6 community [default|hostname|network/bits [oid|-V view [context]]]
rwuser user [noauth|auth|priv [oid|-V view [context]]]
rouser user [noauth|auth|priv [oid|-V view [context]]]
createUser username [-e ENGINEID] (MD5|SHA|SHA-512|SHA-384|SHA-256|SHA-224|default) authpassphrase [(DES|AES|default) [privpassphrase]]
dlmod module-name module-path
sysdescr description
syslocation location
syscontact contact-name
sysname node-name
sysservices NUMBER
sysobjectid OID
skipNFSInHostResources (1|yes|true|0|no|false)
realStorageUnits (1|yes|true|0|no|false)
storageUseNFS 1 | 2 (1 = enable, 2 = disable)
count_kthreads 0|1 0 to exclude kernel threads from hrSystemProcesses.0
ignoredisk name
interface name type speed
ifmib_max_num_ifaces IF-MIB MAX Number of ifaces
include_ifmib_iface_prefix IF-MIB iface names included
defDomain application domain
defTarget application domain target
sourceFilterType none|acceptlist|blocklist
sourceFilterAddress host
engineID string
engineIDType num
engineIDNic string
interface_fadeout interface_fadeout seconds
interface_replace_old interface_replace_old yes|no In snmp.conf and snmp.local.conf:
extraX509SubDir string
x509CRLFile string
tlsAlgorithms string
localCert string
peerCert string
alias NAME TRANSPORT_DEFINITION
doDebugging (1|0)
debugTokens token[,token...]
debugLogLevel (emerg|alert|crit|err|warning|notice|info|debug)
logTimestamp (1|yes|true|0|no|false)
logOption string
mibdirs [mib-dirs|+mib-dirs|-mib-dirs]
mibs [mib-tokens|+mib-tokens]
mibfile mibfile-to-read
showMibErrors (1|yes|true|0|no|false)
commentToEOL (1|yes|true|0|no|false)
strictCommentTerm (1|yes|true|0|no|false)
mibAllowUnderline (1|yes|true|0|no|false)
mibWarningLevel integerValue
mibReplaceWithLatest (1|yes|true|0|no|false)
printNumericEnums (1|yes|true|0|no|false)
printNumericOids (1|yes|true|0|no|false)
escapeQuotes (1|yes|true|0|no|false)
dontBreakdownOids (1|yes|true|0|no|false)
quickPrinting (1|yes|true|0|no|false)
numericTimeticks (1|yes|true|0|no|false)
oidOutputFormat integerValue
suffixPrinting integerValue
extendedIndex (1|yes|true|0|no|false)
printHexText (1|yes|true|0|no|false)
printValueOnly (1|yes|true|0|no|false)
dontPrintUnits (1|yes|true|0|no|false)
hexOutputLength integerValue
dumpPacket (1|yes|true|0|no|false)
reverseEncodeBER (1|yes|true|0|no|false)
defaultPort integerValue
disableSNMPv3 (1|yes|true|0|no|false)
disableSNMPv1 (1|yes|true|0|no|false)
disableSNMPv2c (1|yes|true|0|no|false)
defCommunity string
noTokenWarnings (1|yes|true|0|no|false)
noRangeCheck (1|yes|true|0|no|false)
persistentDir string
tempFilePattern string
noDisplayHint (1|yes|true|0|no|false)
16bitIDs (1|yes|true|0|no|false)
clientaddr string
clientaddrUsesPort (1|yes|true|0|no|false)
serverSendBuf integerValue
serverRecvBuf integerValue
clientSendBuf integerValue
clientRecvBuf integerValue
sendMessageMaxSize integerValue
noPersistentLoad (1|yes|true|0|no|false)
noPersistentSave (1|yes|true|0|no|false)
noContextEngineIDDiscovery (1|yes|true|0|no|false)
timeout integerValue
retries integerValue
outputPrecision string
defDomain application domain
defTarget application domain target
dontLoadHostConfig (1|yes|true|0|no|false)
defSecurityModel string
tsmUseTransportPrefix (1|yes|true|0|no|false)
defAuthType MD5|SHA|SHA-512|SHA-384|SHA-256|SHA-224
defPrivType DES|AES|AES-128
defSecurityName string
defContext string
defPassphrase string
defAuthPassphrase string
defPrivPassphrase string
defAuthMasterKey string
defPrivMasterKey string
defAuthLocalizedKey string
defPrivLocalizedKey string
defVersion 1|2c|3
defSecurityLevel noAuthNoPriv|authNoPriv|authPriv
trustCert trustCert FINGERPRINT|FILENAME In agentx.conf and agentx.local.conf:
agentxsocket AgentX bind address
agentxRetries AgentX Retries
agentxTimeout AgentX Timeout (seconds)
agentxperms AgentX socket permissions: socket_perms [directory_perms [username|userid [groupname|groupid]]]
Который не включает pass
или pass_persist
. Нет «действительно хорошей» документации по параметрам сборки, но я смог найти эту проблему с net-snmp на GitHub, которая дала мне подсказку.
В BuildRoot в «Сборку с этими модулями MIB» необходимо добавить следующее:
agent/extend ucd-snmp/pass ucd-snmp/pass_persist ucd-snmp/proxy ucd-snmp/pass_common util_funcs/restart
Удалите каталог build/netsnmp-5.9
в каталоге buildroot/output/
, чтобы принудительно перестроить этот модуль. Восстановите Buildroot.
Теперь при запуске команды
snmpd -Dmib_init -H
Результаты в следующем:
Configuration directives understood:
In snmpd.conf and snmpd.local.conf:
authtrapenable 1 | 2 (1 = enable, 2 = disable)
trapsink [-profile p] [-name n] [-tag t] host [community] [port]
trap2sink [-profile p] [-name n] [-tag t] host [community] [port]
informsink [-profile p] [-name n] [-tag t] host [community] [port]
trapsess [-profile p] [-name n] [-tag t] [snmpcmdargs] host
trapcommunity community-string
v1trapaddress string
agentuser userid
agentgroup groupid
agentaddress SNMP bind address
quit (1|yes|true|0|no|false)
leave_pidfile (1|yes|true|0|no|false)
dontLogTCPWrappersConnects (1|yes|true|0|no|false)
maxGetbulkRepeats integerValue
maxGetbulkResponses integerValue
avgBulkVarbindSize integerValue
pduStatsMax integerValue
pduStatsThreshold integerValue
injectHandler injectHandler NAME INTONAME [BEFORE_OTHER_NAME]
table tableoid
add_row table_name indexes... values...
agentxsocket AgentX bind address
agentxRetries AgentX Retries
agentxTimeout AgentX Timeout (seconds)
master specify 'agentx' for AgentX support
agentxperms AgentX socket permissions: socket_perms [directory_perms [username|userid [groupname|groupid]]]
com2sec [-Cn CONTEXT] secName IPv4-network-address[/netmask] community
com2sec6 [-Cn CONTEXT] secName IPv6-network-address[/netmask] community
com2secunix [-Cn CONTEXT] secName sockpath community
certSecName certSecName PRIORITY FINGERPRINT [--shaNN|md5] <--sn SECNAME | --rfc822 | --dns | --ip | --cn | --any>
snmpTlstmParams snmpTlstmParams targetParamsName hashType:fingerPrint
snmpTlstmAddr snmpTlstmAddr targetAddrName hashType:fingerprint serverIdentity
group name v1|v2c|usm|... security
access name context model level prefix read write notify
setaccess name context model level prefix viewname viewval
view name type subtree [mask]
authcommunity authtype1,authtype2 community [default|hostname|network/bits [oid|-V view [context]]]
authuser authtype1,authtype2 [-s secmodel] user [noauth|auth|priv [oid|-V view [context]]]
authgroup authtype1,authtype2 [-s secmodel] group [noauth|auth|priv [oid|-V view [context]]]
authaccess name authtype1,authtype2 [-s secmodel] group view [noauth|auth|priv [context|context*]]
rwcommunity community [default|hostname|network/bits [oid|-V view [context]]]
rocommunity community [default|hostname|network/bits [oid|-V view [context]]]
rwcommunity6 community [default|hostname|network/bits [oid|-V view [context]]]
rocommunity6 community [default|hostname|network/bits [oid|-V view [context]]]
rwuser user [noauth|auth|priv [oid|-V view [context]]]
rouser user [noauth|auth|priv [oid|-V view [context]]]
createUser username [-e ENGINEID] (MD5|SHA|SHA-512|SHA-384|SHA-256|SHA-224|default) authpassphrase [(DES|AES|default) [privpassphrase]]
dlmod module-name module-path
** pass miboid command
** pass_persist miboid program
proxy [snmpcmd args] host oid [remoteoid]
sysdescr description
syslocation location
syscontact contact-name
sysname node-name
sysservices NUMBER
sysobjectid OID
skipNFSInHostResources (1|yes|true|0|no|false)
realStorageUnits (1|yes|true|0|no|false)
storageUseNFS 1 | 2 (1 = enable, 2 = disable)
count_kthreads 0|1 0 to exclude kernel threads from hrSystemProcesses.0
ignoredisk name
interface name type speed
ifmib_max_num_ifaces IF-MIB MAX Number of ifaces
include_ifmib_iface_prefix IF-MIB iface names included
defDomain application domain
defTarget application domain target
sourceFilterType none|acceptlist|blocklist
sourceFilterAddress host
engineID string
engineIDType num
engineIDNic string
interface_fadeout interface_fadeout seconds
interface_replace_old interface_replace_old yes|no
In snmp.conf and snmp.local.conf:
extraX509SubDir string
x509CRLFile string
tlsAlgorithms string
localCert string
peerCert string
alias NAME TRANSPORT_DEFINITION
doDebugging (1|0)
debugTokens token[,token...]
debugLogLevel (emerg|alert|crit|err|warning|notice|info|debug)
logTimestamp (1|yes|true|0|no|false)
logOption string
mibdirs [mib-dirs|+mib-dirs|-mib-dirs]
mibs [mib-tokens|+mib-tokens]
mibfile mibfile-to-read
showMibErrors (1|yes|true|0|no|false)
commentToEOL (1|yes|true|0|no|false)
strictCommentTerm (1|yes|true|0|no|false)
mibAllowUnderline (1|yes|true|0|no|false)
mibWarningLevel integerValue
mibReplaceWithLatest (1|yes|true|0|no|false)
printNumericEnums (1|yes|true|0|no|false)
printNumericOids (1|yes|true|0|no|false)
escapeQuotes (1|yes|true|0|no|false)
dontBreakdownOids (1|yes|true|0|no|false)
quickPrinting (1|yes|true|0|no|false)
numericTimeticks (1|yes|true|0|no|false)
oidOutputFormat integerValue
suffixPrinting integerValue
extendedIndex (1|yes|true|0|no|false)
printHexText (1|yes|true|0|no|false)
printValueOnly (1|yes|true|0|no|false)
dontPrintUnits (1|yes|true|0|no|false)
hexOutputLength integerValue
dumpPacket (1|yes|true|0|no|false)
reverseEncodeBER (1|yes|true|0|no|false)
defaultPort integerValue
disableSNMPv3 (1|yes|true|0|no|false)
disableSNMPv1 (1|yes|true|0|no|false)
disableSNMPv2c (1|yes|true|0|no|false)
defCommunity string
noTokenWarnings (1|yes|true|0|no|false)
noRangeCheck (1|yes|true|0|no|false)
persistentDir string
tempFilePattern string
noDisplayHint (1|yes|true|0|no|false)
16bitIDs (1|yes|true|0|no|false)
clientaddr string
clientaddrUsesPort (1|yes|true|0|no|false)
serverSendBuf integerValue
serverRecvBuf integerValue
clientSendBuf integerValue
clientRecvBuf integerValue
sendMessageMaxSize integerValue
noPersistentLoad (1|yes|true|0|no|false)
noPersistentSave (1|yes|true|0|no|false)
noContextEngineIDDiscovery (1|yes|true|0|no|false)
timeout integerValue
retries integerValue
outputPrecision string
defDomain application domain
defTarget application domain target
dontLoadHostConfig (1|yes|true|0|no|false)
defSecurityModel string
tsmUseTransportPrefix (1|yes|true|0|no|false)
defAuthType MD5|SHA|SHA-512|SHA-384|SHA-256|SHA-224
defPrivType DES|AES|AES-128
defSecurityName string
defContext string
defPassphrase string
defAuthPassphrase string
defPrivPassphrase string
defAuthMasterKey string
defPrivMasterKey string
defAuthLocalizedKey string
defPrivLocalizedKey string
defVersion 1|2c|3
defSecurityLevel noAuthNoPriv|authNoPriv|authPriv
trustCert trustCert FINGERPRINT|FILENAME
In agentx.conf and agentx.local.conf:
agentxsocket AgentX bind address
agentxRetries AgentX Retries
agentxTimeout AgentX Timeout (seconds)
agentxperms AgentX socket permissions: socket_perms [directory_perms [username|userid [groupname|groupid]]]
Который теперь включает директивы pass
и pass_persist
. Надеюсь, это сэкономит кому-то день гугления, который я потратил впустую, находя это.