SNMP MIB SMIv2 Conformance Group Issue - snmp

I have a MIB that I started working on but smilint complains about a missing conformance group. How do I add this conformance group to my file?
BLEH-PRODUCT-MIB DEFINITIONS ::= BEGIN
-- Objects in this MIB are implemented in the local SNMP agent.
IMPORTS
MODULE-IDENTITY, OBJECT-TYPE, Integer32, enterprises
FROM SNMPv2-SMI;
blehProductMIB MODULE-IDENTITY
LAST-UPDATED "201305290000Z"
ORGANIZATION "Bleh Corporation"
CONTACT-INFO " Joe Shmoe
Postal: Bleh Corporation
23 Telnet Road
Ottawa, ON, K1K 1K1
Canada
Tel: +1 555 555 5555 x5555
Fax: +1 555 555 5556
E-mail: joe.shmoe#bleh.com"
DESCRIPTION "MIB module describing Product objects."
REVISION "201305290000Z"
DESCRIPTION "Initial"
::= { bleh 911 }
bleh OBJECT IDENTIFIER ::= { enterprises 54321 }
productStatus OBJECT-TYPE
SYNTAX OCTET STRING (SIZE (0..65535))
MAX-ACCESS read-only
STATUS current
DESCRIPTION "The status of the Product system
Details are shown as text"
::= { blehProductMIB 1 }
binaryProductStatus OBJECT-TYPE
SYNTAX Integer32 (0..1)
MAX-ACCESS read-only
STATUS current
DESCRIPTION "The status of the Product system
Zero is unhealthy and One is healthy"
::= { blehProductMIB 2 }
END
Output of smilint:
$ smilint ./BLEH-PRODUCT-MIB
./BLEH-PRODUCT-MIB:28: warning: node `productStatus' must be contained in at least one conformance group
./BLEH-PRODUCT-MIB:37: warning: node `binaryProductStatus' must be contained in at least one conformance group

It simply means you should define OBJECT-GROUP entities before defining OBJECT-TYPE entities in your MIB document.
Take RFC 1907 as example,
https://www.rfc-editor.org/rfc/rfc1907
snmpGroup OBJECT-GROUP
OBJECTS { snmpInPkts,
snmpInBadVersions,
snmpInASNParseErrs,
snmpSilentDrops,
snmpProxyDrops,
snmpEnableAuthenTraps }
STATUS current
DESCRIPTION
"A collection of objects providing basic instrumentation and
control of an SNMPv2 entity."
::= { snmpMIBGroups 8 }
is defined first, and then
snmpInPkts OBJECT-TYPE
SYNTAX Counter32
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"The total number of messages delivered to the SNMP entity
from the transport service."
::= { snmp 1 }
About why groups are important, you can read RFC 2580.
https://www.rfc-editor.org/rfc/rfc2580
Since you are going to define groups, then adding associated MODULE-COMPLIANCE is recommended.

This comes a bit late but I was lately struggling with how OBJECT-GROUP, NOTIFICATION-GROUP, MODULE-COMPLIANCE. smilint was giving me errors. Then I just put all the pieces together and created this. Now it passes even with the autistic smilint -l 6
TEMPORARY-RESEARCH-MIB DEFINITIONS ::= BEGIN
IMPORTS
MODULE-IDENTITY, OBJECT-TYPE, enterprises, Integer32, NOTIFICATION-TYPE FROM SNMPv2-SMI
OBJECT-GROUP, NOTIFICATION-GROUP, MODULE-COMPLIANCE FROM SNMPv2-CONF;
exampleCorp MODULE-IDENTITY
LAST-UPDATED "202111241500Z"
ORGANIZATION
"Example corp ltd"
CONTACT-INFO
"Example corp address"
DESCRIPTION
"This MIB file contains definitions for the
Example corps next coolest product!"
REVISION "202111241500Z"
DESCRIPTION
"MIB file created"
::= { enterprises 55555 }
theSystem OBJECT IDENTIFIER ::= { exampleCorp 10 }
mibMeta OBJECT IDENTIFIER ::= { theSystem 1 }
productTypeOne OBJECT IDENTIFIER ::= { theSystem 2 }
productObjects OBJECT-GROUP
OBJECTS {
devTempAlarm,
devVoltAlarm
}
STATUS current
DESCRIPTION
"A collection of objects providing support for
the system MIB."
::= { mibMeta 1 }
productNotifications NOTIFICATION-GROUP
NOTIFICATIONS {
problemsTrap
}
STATUS current
DESCRIPTION
"A collection of notifications providing support for
the system MIB."
::= { mibMeta 2 }
productCompliances MODULE-COMPLIANCE
STATUS current
DESCRIPTION
"Compliance statement for the the entities in this (theSystem) MIB."
MODULE
MANDATORY-GROUPS {
productObjects,
productNotifications
}
::= { mibMeta 3 }
-- Traps parent need to be always SOMEOID.0.
-- Ie, the zero is important.
trapsOne OBJECT IDENTIFIER ::= { productTypeOne 0 }
problemsTrap NOTIFICATION-TYPE
STATUS current
DESCRIPTION
"This trap is send automatically if problems are detected."
::= { trapsOne 1 }
trapDataTable OBJECT-TYPE
SYNTAX SEQUENCE OF DevEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION
"The table of Devices."
::= { productTypeOne 1 }
trapDataTableEntry OBJECT-TYPE
SYNTAX DevEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION
"The entry to show a row of device information."
INDEX { devIndex }
::= { trapDataTable 1 }
DevEntry ::= SEQUENCE {
devIndex Integer32,
devTempAlarm Integer32,
devVoltAlarm Integer32
}
devIndex OBJECT-TYPE
SYNTAX Integer32(1..5)
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION
"A unique value to index the device."
::= { trapDataTableEntry 1 }
devTempAlarm OBJECT-TYPE
SYNTAX Integer32(0..1)
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"The state of the device temperature alarm:
0 = Alarm OFF,
1 = Alarm ON"
::= { trapDataTableEntry 2 }
devVoltAlarm OBJECT-TYPE
SYNTAX Integer32(0..1)
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"The state of the device voltage alarm:
0 = Alarm OFF,
1 = Alarm ON"
::= { trapDataTableEntry 3 }
END

Related

Facing issue "TypeError: resolveWithMib() takes exactly 2 arguments (3 given)" with resolveWithMib in 4.4.12 . It was working in 4.4.4

I am using python 2.7 and pysnmp 4.1.12 . The following code is having some trouble with resolveWithMib function. It is working with internal MIBs like SNMPv2-MIB , but not with my private MIB.
Actually I am getting "TypeError: resolveWithMib() takes exactly 2 arguments (3 given)" . on pysnmp 4.4.12. It worked fine on 4.4.4
I pass json objects like this
passing json object {'vmUserName': 'admin', 'partitionCpuUsage': 3.0}
def sendTrap_gen(self, event, eventvals):
mibViewController = view.MibViewController(self.snmpEngine.getMibBuilder())
# Create Notification Originator App instance.
ntfOrg = ntforg.NotificationOriginator()
ntfOrg.snmpContext = self.snmpContext
trapName = rfc1902.ObjectIdentity('PARTITION-MIB', event)
ntfOrg.sendVarBinds(
self.snmpEngine,
'my-notification', # notification targets
None, '', # contextEngineId, contextName
rfc1902.NotificationType(
trapName,
objects={('PARTITION-MIB', k): v for k, v in eventvals.items()}
).resolveWithMib(mibViewController)
)
The mib entry is like this
partitionCpuUsage OBJECT-TYPE
SYNTAX DisplayString (SIZE (0..100))
MAX-ACCESS accessible-for-notify
STATUS current
DESCRIPTION
"partition CPU Usage"
::= { partitionNotfsParams 7 }
partitionCpuUsageReachedTheThreshold NOTIFICATION-TYPE
OBJECTS { vmUserName, partitionCpuUsage }
STATUS current
DESCRIPTION
"This notfication for System cpu usage reached the threshold"
::= { partitionNotfs 1 }
partitionCpuUsage OBJECT-TYPE
SYNTAX DisplayString (SIZE (0..100))
MAX-ACCESS accessible-for-notify
STATUS current
DESCRIPTION
"partition CPU Usage"
::= { partitionNotfsParams 7 }

Getting vehicle ID

I am trying to get vehicle id as follow:
mobility = TraCIMobilityAccess().get(getParentModule());
assert(mobility);
traci = mobility->getCommandInterface();
traciVehicle = mobility->getVehicleCommandInterface();
cout<< mobility->getExternalId();
But it returns an invalid vehicle id. What is wrong?
Please help me to solve this problem. Thanks.
What do you mean by an invalid vehicle id? The way you are getting the identifier is the one used by sumo. If that is the case, can you specify what do you expect as an identifier? (that of omnet which starts from [1]?)
As the id of SUMO and that one apparent in omnet are not the same (the order of creation), you may add the following to get your own id (that matches the one of omnet) :
in the ".h" file of your TraCIDemo11p, add your id:
protected:
int your_id;//added
in the ".c" file of your TraCIDemo11p, affect the index in your id:
if (stage == 0) {
...
your_id = getParentModule()->getIndex();//added
...
next, in the place you want to verify a statement, add this:
EV << "My SUMO id = " << mobility->getExternalId() << endl;
EV << "My VEINS id = " << your_id /*or just : getParentModule()->getIndex()*/<< endl;
I hope this helps.
You can try the FindModlue::findHost() in DemoBaseApplLayer::initialize(int stage) in DemoBaseApplLayer.cc:
EV << FindModule<BaseMobility*>::findHost(getParentModule())->getId() << endl;
It will first return the host module and then use the getId() function to get its id.
For better understanding:
Firstly, you can run the simulation to see the indexing of the whole simulation and it would be like this:
Simulation information in veins
As read from the figure, each objects are assigned to a number, e.g. node[0]has the id 7, besides that, each sub-modules are also assigned with id numbers, e.g.
node[0] id = 7
appl id = 8
nic id = 9
veinsmobility id = 10
All of this ids (7,8,9,10) point to the node[0], which means you can use thoese ids to identify a specific car.
In the default DemoBaseApplLayer.cc, you can find
mac = FindModule<DemoBaseApplLayerToMac1609_4Interface*>::findSubModule(getParentModule());
and
myId = mac->getMACAddress();
in the initialization function void DemoBaseApplLayer::initialize(int stage).
Therefore, you can already use the myId as the vehicle id.
By the way, the reason that you get the 18 and 20 for vehicle id, is that the returned module might just be the host module and the sub-module, e.g. 18 is for the node[*] and the 20 is for its nic sub-module.

Mapping numeric value in OpenHab2 to String

I added Homematic HM-CC-RT-DN thermostats by connecting a CCU2 to OpenHab2.
Then I defined the thermostats as items for HomeKit to use:
Group gBedroomThermostat "Bedroom Thermostat" [ "Thermostat" ]
Number BedroomThermostatCurrentTemp "Bedroom Thermostat Current Temperature" (gBedroomThermostat) [ "CurrentTemperature" ] { channel="homematic:HM-CC-RT-DN:xxx:yyy:4#ACTUAL_TEMPERATURE" }
Number BedroomThermostatTargetTemperature "Bedroom Thermostat Target Temperature" (gBedroomThermostat) [ "TargetTemperature" ] { channel="homematic:HM-CC-RT-DN:xxx:yyy:4#SET_TEMPERATURE" }
String BedroomThermostatHeatingCoolingMode "Bedroom Thermostat Heating/Cooling Mode" (gBedroomThermostat) [ "homekit:HeatingCoolingMode" ]
This all works fine, except for the last line in this definition. The thermostats only supply a percentage value of the valve state (homematic:HM-CC-RT-DN:xxx:yyy:4#VALVE_STATE). What I would like to do is to map this percentage value to the String 'Off' if the valve state is 0% and to 'On' otherwise.
I looked into OpenHab2 Transformations (https://github.com/openhab/openhab/wiki/Transformations) but I'm neither sure how to use them in this case, nor where to apply them.

Nesting one template inside another with StringTemplate 4

I am having problem understanding how to nest another template inside another. For example, I have 3 templates: application.stg, wrapper.stg and core.stg.
core.stg:
page(data1, data2) ::= <<
<h1>$data1$</h1>
<h1>$data2$</h1>
>>
wrapper.stg:
page(data3, data4) ::= <<
<h1>$data3$</h1>
<!----- CORE.STG GOES HERE ------->
<h1>$data4$</h1>
>>
application.stg:
page(data7, data8) ::= <<
<h1>$data7$</h1>
<!----- WRAPPER.STG GOES HERE ------->
<h1>$data8$</h1>
>>
The documentation seems to hint that this is possible (Conditional Subtemplate section), but sorry, I could not figure out the syntax at all. Please help me out.
You can create a whole file with every template and make sure you set the .stg extension to it.
Then create a TemplateGroupFile object and set the properties data7 and data8 and tell it to start in the application template.
core(data1, data2) ::= <<
<h1>$data1$</h1>
<h1>$data2$</h1>
>>
wrapper(data3, data4) ::= <<
<h1>$data3$</h1>
core(data3,data4)
<h1>$data4$</h1>
>>
application(data7, data8) ::= <<
<h1>$data7$</h1>
wrapper(data7,data8)
<h1>$data8$</h1>
>>
This is the C# code
TemplateGroupFile grp = new TemplateGroupFile(Template);
Template page_tpl = grp.GetInstanceOf(GroupName);
GroupName = "application";
page_tpl.Add("data7", yourData);
page_tpl.Add("data8", moreOfYourData);
File.WriteAllText(Path.Combine(dir, Path.GetFileName(outputFile)), page_tpl.Render());

how to generate code for MIB table

I have a KAVITA-MIB:
KAVITA-MIB DEFINITIONS ::= BEGIN
IMPORTS
OBJECT-TYPE,MODULE-IDENTITY FROM SNMPv2-SMI
TEXTUAL-CONVENTION FROM SNMPv2-TC;
kavita MODULE-IDENTITY
LAST-UPDATED "200205290000Z" -- 29 May 2002, midnight
ORGANIZATION "net-snmp"
CONTACT-INFO "postal: Wes Hardaker
P.O. Box 382
Davis CA 95617
email: net-snmp-coders#lists.sourceforge.net"
DESCRIPTION "A simple mib for demonstration purposes."
::={enterprises 1100}
RowStatus ::= TEXTUAL-CONVENTION
STATUS current
DESCRIPTION
"The RowStatus textual convention is used to manage the
creation and deletion of conceptual rows, and is used as the
value of the SYNTAX clause for the status column of a
conceptual row."
SYNTAX INTEGER {
-- the following two values are states:
-- these values may be read or written
active(1), -- state: read/write
notInService(2), -- state: read/write
notReady(3), -- state: read only
createAndGo(4), -- action: write only
createAndWait(5), -- action: write only
destroy(6) -- action: write only
}
kavitaScalar OBJECT IDENTIFIER ::= {kavita 1}
kavitaTable OBJECT IDENTIFIER ::= {kavita 2}
scalar1 OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DESCRIPTION "scalar1"
DEFVAL { 2 }
::= { kavitaScalar 1 }
scalar2 OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DESCRIPTION "scalar2"
DEFVAL { 4 }
::= { kavitaScalar 2 }
kavitaTableOne OBJECT-TYPE
SYNTAX SEQUENCE OF kavitaTable1Entry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION "Table 1"
::= { kavitaTable 1 }
kavitaTable1Entry OBJECT-TYPE
SYNTAX kavitaTable1Entry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION "Entry"
INDEX { tIndex }
::= { kavitaTableOne 1 }
kavitaTable1Entry ::= SEQUENCE {
tIndex Integer32,
tName DisplayString,
tMarks Integer32,
tRowStatus INTEGER
}
tIndex OBJECT-TYPE
SYNTAX Integer32 (1..100)
MAX-ACCESS read-only
STATUS current
DESCRIPTION "Index for Table 1"
::= { kavitaTable1Entry 1 }
tName OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-create
STATUS current
DESCRIPTION "Name for Table 1"
::= { kavitaTable1Entry 2 }
tMarks OBJECT-TYPE
SYNTAX Integer32(1..100)
MAX-ACCESS read-create
STATUS current
DESCRIPTION "Marks for Table 1"
::= { kavitaTable1Entry 3 }
tRowStatus OBJECT-TYPE
SYNTAX RowStatus
MAX-ACCESS read-create
STATUS current
DESCRIPTION "The status"
::= { kavitaTable1Entry 4 }
END
How should i generate mib2c code for "kavitaTableOne".
I have tried using
env MIBS="+KAVITA-MIB" MIBDIRS="/usr/share/snmp/mibs" mib2c -c mib2c.mfd.conf kavitaTableOne
but it says
Unlinked OID in KAVITA-MIB: kavita ::= { enterprises 1100 }
Undefined identifier: enterprises near line 7 of /usr/share/snmp/mibs/KAVITA-MIB.txt
This module can only be used with tables, not branches or entire MIBs.
Please specify and OID that is a table. (OID: kavitaTableOne)
Kindly help..
In the top of your MIB you may first repeat :
kavita OBJECT IDENTIFIER ::= { enterprises 1100 }
after that try to compile with :
env MIBS="+KAVITA-MIB" mib2c kavitaTable
You are missing to import enterprises:
IMPORTS
OBJECT-TYPE,MODULE-IDENTITY,enterprises FROM SNMPv2-SMI

Resources