Название: Net-SNMP, mib2c
Отправлено: demaker от Апрель 21, 2022, 13:02
Доброго дня! Кто-нибудь работал с net- snmp и генерил файлы с кодом с помощью утилиты mib2c?
Название: Re: Net-SNMP, mib2c
Отправлено: qtkoder777 от Апрель 21, 2022, 13:15
ИИ работал. Осваивайте кодогенератор на базе GPT-3.
Название: Re: Net-SNMP, mib2c
Отправлено: demaker от Апрель 21, 2022, 14:04
Есть мибовский файл. С помощью утилиты snmptranslate можно работать с oid. Не могу понять как с помощью mib2c сгенерить код. mib2c -c mib2c. mfd. conf что писать здесь?
Наименование таблицы, имя переменной, наименование идентификатора из mib - файла? Если указываю один из вышеперечисленных параметров, то выдается ошибка This module can be used with tables, not branches or entire MIBs. Please specify and OID that is a table. (OID: имя папретра)
Название: Re: Net-SNMP, mib2c
Отправлено: tux от Апрель 22, 2022, 00:39
https://www.opennet.ru/man.shtml?topic=mib2c&category=1&russian=2 https://stackoverflow.com/questions/11131696/how-to-use-the-mib2c-command
Название: Re: Net-SNMP, mib2c
Отправлено: demaker от Апрель 22, 2022, 11:43
https://www.opennet.ru/man.shtml?topic=mib2c&category=1&russian=2 https://stackoverflow.com/questions/11131696/how-to-use-the-mib2c-command
MIB-file: afdxSwitchLowBagValueLoopbackTestResult OBJECT-TYPE SYNTAX INTEGER { passed (1), failed (2) } ACCESS read-only STATUS current DESCRIPTION "The result of the Low Bag Value Loopback test executed on ground. The possible values are: - passed (1), - failed (2)." ::= { afdxSwitchPrivate 2 }
export MIBS="/home/robo/netsnmp/afdxswitch.mib"
Правильно ли выполняю работу с утилитой mib2c для переменной afdxSwitchTimestampCounterTestResult mib2c -c mib2c.scalar.conf afdxSwitchLowBagValueLoopbackTestResult
Так как в результате получаю с-файл C++ (Qt) #include <net-snmp/net-snmp-config.h> #include <net-snmp/net-snmp-includes.h> #include <net-snmp/agent/net-snmp-agent-includes.h> #include "afdxSwitchLowBagValueLoopbackTestResult.h" /** Initializes the afdxSwitchLowBagValueLoopbackTestResult module */ void init_afdxSwitchLowBagValueLoopbackTestResult(void) { const oid afdxSwitchLowBagValueLoopbackTestResult_oid[] = { 1,3,6,1,4,1,8419,11,1,2 }; DEBUGMSGTL(("afdxSwitchLowBagValueLoopbackTestResult", "Initializing\n")); netsnmp_register_scalar( netsnmp_create_handler_registration("afdxSwitchLowBagValueLoopbackTestResult", handle_afdxSwitchLowBagValueLoopbackTestResult, afdxSwitchLowBagValueLoopbackTestResult_oid, OID_LENGTH(afdxSwitchLowBagValueLoopbackTestResult_oid), HANDLER_CAN_RONLY )); } int handle_afdxSwitchLowBagValueLoopbackTestResult(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { /* We are never called for a GETNEXT if it's registered as a "instance", as it's "magically" handled for us. */ /* a instance handler also only hands us one request at a time, so we don't need to loop over a list of requests; we'll only get one. */ switch(reqinfo->mode) { case MODE_GET: snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, //_____________Что с этим делать?_________________ //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! /* XXX: a pointer to the scalar's data */, /* XXX: the length of the data in bytes */); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! break; default: /* we should never get here, so this is a really bad error */ snmp_log(LOG_ERR, "unknown mode (%d) in handle_afdxSwitchLowBagValueLoopbackTestResult\n", reqinfo->mode ); return SNMP_ERR_GENERR; } return SNMP_ERR_NOERROR; }
И что я должен дописать вместо этого я не знаю /* XXX: a pointer to the scalar's data */, /* XXX: the length of the data in bytes */
Название: Re: Net-SNMP, mib2c
Отправлено: tux от Апрель 22, 2022, 12:37
Так как в результате получаю с-файл
А что вы в результате хотели получить, если mib2c -- generate template code for extending the agent
Эта утилита просто генерирует заготовку, а чем вы её будете заполнять - ваше дело. И не забудьте повнимательнее прочесть документацию.
Название: Re: Net-SNMP, mib2c
Отправлено: qtkoder777 от Апрель 23, 2022, 04:13
А заполняет пусть ИИ. Натравите GPT-3 на эту заготовку.
Название: Re: Net-SNMP, mib2c
Отправлено: demaker от Апрель 24, 2022, 00:36
С mib2c вроде разобрались. Файлы .h .cpp - есть. Перенес файлы в /agent/mibgroup/ ./configure --with-mib-modules="name"
Запускаем агента cd /usr/local/sbin/ ./snmpd
Запустил snmpget snmpget -v2c -c public localhost 1.3.6.1.4.1.8419.11.1.1 Timeout: No Response from localhost.
??? Смотрим лог-файл /var/log/snmp.log Warning: no access control information configured. (Config search path: /usr/local/etc/snmp:/usr/local/share/snmp:/usr/local/lib/snmp:/home/evgen/.snmp) It's unlikely this agent can serve any useful purpose in this state. Run "snmpconf -g basic_setup" to help you configure the snmpd.conf file for this agent. NET-SNMP version 5.9.1
Конфигурационный файл как я понял при запуске ./configure нахлдится /var/net-snmp/snmpd.conf Что в нем нужно прописать ???
Название: Re: Net-SNMP, mib2c
Отправлено: tux от Апрель 24, 2022, 13:59
https://www.opennet.ru/man.shtml?topic=snmpd.conf&category=5&russian=3 https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-an-snmp-daemon-and-client-on-ubuntu-18-04-ru
Название: Re: Net-SNMP, mib2c
Отправлено: demaker от Апрель 29, 2022, 11:54
Не выполняется snmpget ??? ??? ??? snmpset -v2c -c public localhost .1.3.6.1.4.1.8419.11.1.1.0 = 5
Error in packet. Reason: (genError) A general failure occured
Хотя snmpget, snmpwalk отрабатывают норм snmpget -v2c -c public localhost .1.3.6.1.4.1.8419.11.1.1.0 AIRBUS-AFDX-SW-MIB::afdxSwitchEDACTestResult.0 = INTEGER: 10
snmpwalk -v2c -c public localhost .1.3.6.1.4.1.8419.11.1.1.0 AIRBUS-AFDX-SW-MIB::afdxSwitchEDACTestResult.0 = INTEGER: 10
В MIB-файле ACCESS read-write MIB - файл AIRBUS-AFDX-SW-MIB DEFINITIONS ::= BEGIN
IMPORTS enterprises, Counter, IpAddress, TimeTicks FROM RFC1155-SMI TRAP-TYPE FROM RFC-1215 OBJECT-TYPE FROM RFC-1212; collins-Avionics OBJECT IDENTIFIER ::= { enterprises 8419 } AFDX OBJECT IDENTIFIER ::= { collins-Avionics 11 }
-- Groups in AIRBUS AFDX Switch MIB afdxSwitchPrivate OBJECT IDENTIFIER ::= { AFDX 1 }
-- -- The afdxSwitchPrivate group -- -- The afdxSwitchPrivate group contains objects related to the RC Switch -- internal architecture. --
afdxSwitchEDACTestResult OBJECT-TYPE SYNTAX INTEGER { passed (1), failed (2) } ACCESS read-write STATUS current DESCRIPTION "The result of the EDAC test executed on ground. The possible values are: - passed (1), - failed (2)." ::= { afdxSwitchPrivate 1 }
END
В конфиге rwcommunity public localhost файл /usr/local/share/snmpd.conf ############################################################################### # # EXAMPLE.conf: # An example configuration file for configuring the Net-SNMP agent ('snmpd') # See the 'snmpd.conf(5)' man page for details # # Some entries are deliberately commented out, and will need to be explicitly activated # ############################################################################### # # AGENT BEHAVIOUR #
# Listen for connections from the local system only agentAddress udp:127.0.0.1:161 # Listen for connections on all interfaces (both IPv4 *and* IPv6) #agentAddress udp:161,udp6:[::1]:161
############################################################################### # # SNMPv3 AUTHENTICATION # # Note that these particular settings don't actually belong here. # They should be copied to the file /var/lib/snmp/snmpd.conf # and the passwords changed, before being uncommented in that file *only*. # Then restart the agent
# createUser authOnlyUser MD5 "remember to change this password" # createUser authPrivUser SHA "remember to change this one too" DES # createUser internalUser MD5 "this is only ever used internally, but still change the password"
# If you also change the usernames (which might be sensible), # then remember to update the other occurances in this example config file to match.
############################################################################### # # ACCESS CONTROL #
# system + hrSystem groups only view systemonly included .1.3.6.1.2.1.1 view systemonly included .1.3.6.1.2.1.25.1 view all included .1 # Full access from the local host #rocommunity public localhost rwcommunity public localhost # Default access to basic system info rocommunity public default -V systemonly # rocommunity6 is for IPv6 rocommunity6 public default -V systemonly
# Full access from an example network # Adjust this network address to match your local # settings, change the community string, # and check the 'agentAddress' setting above #rocommunity secret 10.0.0.0/16
# Full read-only access for SNMPv3 rouser authOnlyUser # Full write access for encrypted requests # Remember to activate the 'createUser' lines above # rwuser authPrivUser priv
# It's no longer typically necessary to use the full 'com2sec/group/access' configuration # r[ow]user and r[ow]community, together with suitable views, should cover most requirements
############################################################################### # # SYSTEM INFORMATION #
# Note that setting these values here, results in the corresponding MIB objects being 'read-only' # See snmpd.conf(5) for more details sysLocation Sitting on the Dock of the Bay sysContact Me <me@example.org> # Application + End-to-End layers sysServices 72
# # Process Monitoring # # At least one 'mountd' process proc mountd # No more than 4 'ntalkd' processes - 0 is OK proc ntalkd 4 # At least one 'sendmail' process, but no more than 10 proc sendmail 10 1
# Walk the UCD-SNMP-MIB::prTable to see the resulting output # Note that this table will be empty if there are no "proc" entries in the snmpd.conf file
# # Disk Monitoring # # 10MBs required on root disk, 5% free on /var, 10% free on all other disks disk / 10000 disk /var 5% includeAllDisks 10%
# Walk the UCD-SNMP-MIB::dskTable to see the resulting output # Note that this table will be empty if there are no "disk" entries in the snmpd.conf file
# # System Load # # Unacceptable 1-, 5-, and 15-minute load averages load 12 10 5
# Walk the UCD-SNMP-MIB::laTable to see the resulting output # Note that this table *will* be populated, even without a "load" entry in the snmpd.conf file
############################################################################### # # ACTIVE MONITORING #
# send SNMPv1 traps trapsink localhost public # send SNMPv2c traps #trap2sink localhost public # send SNMPv2c INFORMs #informsink localhost public
# Note that you typically only want *one* of these three lines # Uncommenting two (or all three) will result in multiple copies of each notification.
# # Event MIB - automatically generate alerts # # Remember to activate the 'createUser' lines above iquerySecName internalUser rouser internalUser # generate traps on UCD error conditions defaultMonitors yes # generate traps on linkUp/Down linkUpDownNotifications yes
############################################################################### # # EXTENDING THE AGENT #
# # Arbitrary extension commands # extend test1 /bin/echo Hello, world! extend-sh test2 echo Hello, world! ; echo Hi there ; exit 35 #extend-sh test3 /bin/sh /tmp/shtest
# Note that this last entry requires the script '/tmp/shtest' to be created first, # containing the same three shell commands, before the line is uncommented
# Walk the NET-SNMP-EXTEND-MIB tables (nsExtendConfigTable, nsExtendOutput1Table # and nsExtendOutput2Table) to see the resulting output
# Note that the "extend" directive supercedes the previous "exec" and "sh" directives # However, walking the UCD-SNMP-MIB::extTable should still returns the same output, # as well as the fuller results in the above tables.
# # "Pass-through" MIB extension command # #pass .1.3.6.1.4.1.8072.2.255 /bin/sh PREFIX/local/passtest #pass .1.3.6.1.4.1.8072.2.255 /usr/bin/perl PREFIX/local/passtest.pl
# Note that this requires one of the two 'passtest' scripts to be installed first, # before the appropriate line is uncommented. # These scripts can be found in the 'local' directory of the source distribution, # and are not installed automatically.
# Walk the NET-SNMP-PASS-MIB::netSnmpPassExamples subtree to see the resulting output
# # AgentX Sub-agents # # Run as an AgentX master agent master agentx # Listen for network connections (from localhost) # rather than the default named socket /var/agentx/master #agentXSocket tcp:localhost:705
setserialno 462583681 ############################################################## # # snmpNotifyFilterTable persistent data # ##############################################################
engineBoots 28 oldEngineID 0x80001f888025d749712555646200000000 ############################################################## # # ifXTable persistent data # ifXTable .1 14:0 18:0x $ ifXTable .2 14:0 18:0x $ ifXTable .3 14:0 18:0x $ ##############################################################
Код обработчика агента C++ (Qt) /* * Note: this file originally auto-generated by mib2c * using mib2c.scalar.conf */ #include <net-snmp/net-snmp-config.h> #include <net-snmp/net-snmp-includes.h> #include <net-snmp/agent/net-snmp-agent-includes.h> #include "collins_Avionics.h" static u_char mydata = 10; /** Initializes the collins_Avionics module */ void init_collins_Avionics(void) { const oid afdxSwitchEDACTestResult_oid[] = { 1,3,6,1,4,1,8419,11,1,1 }; DEBUGMSGTL(("collins_Avionics", "Initializing\n")); netsnmp_register_scalar( netsnmp_create_handler_registration("afdxSwitchEDACTestResult", handle_afdxSwitchEDACTestResult, afdxSwitchEDACTestResult_oid, OID_LENGTH(afdxSwitchEDACTestResult_oid), HANDLER_CAN_RWRITE )); } int handle_afdxSwitchEDACTestResult(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { int ret; /* We are never called for a GETNEXT if it's registered as a "instance", as it's "magically" handled for us. */ /* a instance handler also only hands us one request at a time, so we don't need to loop over a list of requests; we'll only get one. */ switch(reqinfo->mode) { case MODE_GET: case MODE_GETNEXT: snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, &mydata /* XXX: a pointer to the scalar's data */, sizeof(mydata) /* XXX: the length of the data in bytes */); break; /* * SET REQUEST * * multiple states in the transaction. See: * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg */ //case MODE_SET_RESERVE1: // /* or you could use netsnmp_check_vb_type_and_size instead */ // ret = netsnmp_check_vb_type(requests->requestvb, ASN_INTEGER); // if ( ret != SNMP_ERR_NOERROR ) { // netsnmp_set_request_error(reqinfo, requests, ret ); // } // break; //case MODE_SET_RESERVE2: // /* XXX malloc "undo" storage buffer */ // if (/* XXX if malloc, or whatever, failed: */) { // netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_RESOURCEUNAVAILABLE); // } // break; //case MODE_SET_FREE: // /* XXX: free resources allocated in RESERVE1 and/or // RESERVE2. Something failed somewhere, and the states // below won't be called. */ // break; case MODE_SET_ACTION: ///* XXX: perform the value change here */ mydata = *(requests->requestvb->val.integer); //if (/* XXX: error? */) { // netsnmp_set_request_error(reqinfo, requests, /* some error */); //} break; //case MODE_SET_COMMIT: // /* XXX: delete temporary storage */ // if (/* XXX: error? */) { // /* try _really_really_ hard to never get to this point */ // netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_COMMITFAILED); // } // break; //case MODE_SET_UNDO: // /* XXX: UNDO and return to previous value for the object */ // if (/* XXX: error? */) { // /* try _really_really_ hard to never get to this point */ // netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_UNDOFAILED); // } // break; default: /* we should never get here, so this is a really bad error */ snmp_log(LOG_ERR, "unknown mode (%d) in handle_afdxSwitchEDACTestResult\n", reqinfo->mode ); return SNMP_ERR_GENERR; } return SNMP_ERR_NOERROR; }
Подскажите где может быть загвоздка ??? ??? ???
Название: Re: Net-SNMP, mib2c(Решено)
Отправлено: demaker от Май 04, 2022, 15:38
:) Я зря закомментировал все case ::) кроме case MODE_SET_ACTION из-за этого и выдавалась ошибка C++ (Qt) /* * Note: this file originally auto-generated by mib2c * using mib2c.scalar.conf */ #include <net-snmp/net-snmp-config.h> #include <net-snmp/net-snmp-includes.h> #include <net-snmp/agent/net-snmp-agent-includes.h> #include "collins_Avionics.h" static u_char mydata = 10; /** Initializes the collins_Avionics module */ void init_collins_Avionics(void) { const oid afdxSwitchEDACTestResult_oid[] = { 1,3,6,1,4,1,8419,11,1,1 }; DEBUGMSGTL(("collins_Avionics", "Initializing\n")); netsnmp_register_scalar( netsnmp_create_handler_registration("afdxSwitchEDACTestResult", handle_afdxSwitchEDACTestResult, afdxSwitchEDACTestResult_oid, OID_LENGTH(afdxSwitchEDACTestResult_oid), HANDLER_CAN_RWRITE )); } int handle_afdxSwitchEDACTestResult(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { int ret; /* We are never called for a GETNEXT if it's registered as a "instance", as it's "magically" handled for us. */ /* a instance handler also only hands us one request at a time, so we don't need to loop over a list of requests; we'll only get one. */ switch(reqinfo->mode) { case MODE_GET: case MODE_GETNEXT: snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, &mydata /* XXX: a pointer to the scalar's data */, sizeof(mydata) /* XXX: the length of the data in bytes */); break; /* * SET REQUEST * * multiple states in the transaction. See: * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg */ case MODE_SET_RESERVE1: // /* or you could use netsnmp_check_vb_type_and_size instead */ // ret = netsnmp_check_vb_type(requests->requestvb, ASN_INTEGER); // if ( ret != SNMP_ERR_NOERROR ) { // netsnmp_set_request_error(reqinfo, requests, ret ); // } break; case MODE_SET_RESERVE2: // /* XXX malloc "undo" storage buffer */ // if (/* XXX if malloc, or whatever, failed: */) { // netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_RESOURCEUNAVAILABLE); // } break; case MODE_SET_FREE: // /* XXX: free resources allocated in RESERVE1 and/or // RESERVE2. Something failed somewhere, and the states // below won't be called. */ break; case MODE_SET_ACTION: ///* XXX: perform the value change here */ mydata = *(requests->requestvb->val.integer); //if (/* XXX: error? */) { // netsnmp_set_request_error(reqinfo, requests, /* some error */); //} break; case MODE_SET_COMMIT: // /* XXX: delete temporary storage */ // if (/* XXX: error? */) { // /* try _really_really_ hard to never get to this point */ // netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_COMMITFAILED); // } break; case MODE_SET_UNDO: // /* XXX: UNDO and return to previous value for the object */ // if (/* XXX: error? */) { // /* try _really_really_ hard to never get to this point */ // netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_UNDOFAILED); // } break; default: /* we should never get here, so this is a really bad error */ snmp_log(LOG_ERR, "unknown mode (%d) in handle_afdxSwitchEDACTestResult\n", reqinfo->mode ); return SNMP_ERR_GENERR; } return SNMP_ERR_NOERROR; }
https://sourceforge-net.translate.goog/p/net-snmp/mailman/message/14633956/?_x_tr_sl=en&_x_tr_tl=ru&_x_tr_hl=ru&_x_tr_pto=sc
Название: Re: Net-SNMP, mib2c
Отправлено: demaker от Май 30, 2022, 23:15
И в довершении всего, хотелось бы понять как действовать ситуации когда тип составной(т.е состоит из нескольких параметров) или строка DPS-MIB-V38 DEFINITIONS ::= BEGIN IMPORTS DisplayString FROM RFC1213-MIB OBJECT-TYPE FROM RFC-1212 enterprises FROM RFC1155-SMI;
dpsInc OBJECT IDENTIFIER ::= {enterprises 2682} dpsAlarmControl OBJECT IDENTIFIER ::= {dpsInc 1} tmonXM OBJECT IDENTIFIER ::= {dpsAlarmControl 1} tmonIdent OBJECT IDENTIFIER ::= {tmonXM 1}
tmonIdentManufacturer OBJECT-TYPE SYNTAX DisplayString ACCESS read-only STATUS mandatory DESCRIPTION “The TMON/XM Unit manufacturer.” ::= {tmonIdent 1}
В выше приведенном коде DisplayString FROM RFC1213-MIB является строковым типом DisplayString ::= OCTET STRING
или составной тип AfdxRedundancyStatsEntry AIRBUS-AFDX-SW-MIB DEFINITIONS ::= BEGIN
IMPORTS enterprises, Counter, IpAddress, TimeTicks FROM RFC1155-SMI TRAP-TYPE FROM RFC-1215 OBJECT-TYPE FROM RFC-1212;
... ...
afdxRedundancyStatsEntry OBJECT-TYPE SYNTAX AfdxRedundancyStatsEntry ACCESS read-only STATUS mandatory DESCRIPTION "An entry in the redundancy Stats table" INDEX { afdxRedundancyVLPortIndex, afdxRedundancyVLMacAddress} ::= { afdxRedundancyStatsTable 1 }
AfdxRedundancyStatsEntry ::= SEQUENCE { afdxRedundancyVLPortIndex INTEGER, afdxRedundancyVLMacAddress INTEGER, afdxRedundancyVLIntegrityCheckError Counter, afdxRedundancyVLFirstInFrames Counter }
Список конфиг файлов mib2c.array-user.conf mib2c.create-dataset.conf mib2c.int_watch.conf mib2c.iterate.conf mib2c.iterate_access.conf mib2c.mfd.conf mib2c.notify.conf mib2c.old-api.conf mib2c.scalar.conf
Какой из конфиг-файлов можно или нужно использовать для кодогенерации mib2c??? Я так понимаю
|