owned this note
owned this note
Published
Linked with GitHub
SNMP Data Collection Parsing Example
====
We're talking about the SNMP Collector, not any other collector, as `datacollection-config.xml` is all about building `snmp-collections`.
As mentioned, it is crucial to make a distinction between the following two concepts:
1. Build the effective `snmp-collection` based on the `systemDef` list associated with a given list of `datacollection-groups`.
Build the effective list of `mibObj` to collect from a given node using its `sysObjectID`.
2. The first process starts when the spring context initializes. Of course, it also happens during runtime when a change in `datacollection-config.xml` is detected (not the files inside the `datacollection` directory).
The second process starts every time the SNMP Collector will collect data from the node.
So, as you're mentioning categories and filters, that means we're talking about different `Collectd` packages, so for your example, I would expect to see in `collectd-configuration.xml` the following:
```xml=
<package name="package-1" remote="false">
<filter>catincCatA</filter>
<service name="SNMP" interval="300000" user-defined="false" status="on">
<parameter key="collection" value="group1"/>
</service>
</package>
<package name="package-2" remote="false">
<filter>catincCatB</filter>
<service name="SNMP" interval="300000" user-defined="false" status="on">
<parameter key="collection" value="group2"/>
</service>
</package>
```
Then, in `datacollection-config.xml`, I would expect to see:
```xml=
<snmp-collection name="group1" snmpStorageFlag="select">
<rrd step="300">
<rra>RRA:AVERAGE:0.5:1:2016</rra>
</rrd>
<include-collection dataCollectionGroup="UniqueA"/>
<include-collection dataCollectionGroup="UniqueB"/>
</snmp-collection>
<snmp-collection name="group2" snmpStorageFlag="select">
<rrd step="300">
<rra>RRA:AVERAGE:0.5:1:2016</rra>
</rrd>
<include-collection dataCollectionGroup="UniqueB"/>
<include-collection dataCollectionGroup="UniqueC"/>
</snmp-collection>
```
Then, inside the `datacollection` directory, I'd expect to find 3 files, let's call them `unique-a.xml`, `unique-b.xml` and `unique-c.xml`, with the following content, respectively:
```xml=
<datacollection-group name="UniqueA">
<systemDef name="Collect-A">
<sysoid>.1.100.1.1</sysoid>
<collect>
<includeGroup>test-group-1</includeGroup>
</collect>
</systemDef>
<systemDef name="Collect-B">
<sysoid>.1.100.1.2</sysoid>
<collect>
<includeGroup>test-group-2</includeGroup>
</collect>
</systemDef>
<systemDef name="Collect-C">
<sysoidMask>.1.100.</sysoidMask>
<collect>
<includeGroup>test-group-3</includeGroup>
</collect>
</systemDef>
</datacollection-group>
```
```xml=
<datacollection-group name="UniqueB">
<systemDef name="Collect-D">
<sysoidMask>.1.100.1.</sysoidMask>
<collect>
<includeGroup>test-group-4</includeGroup>
</collect>
</systemDef>
<systemDef name="Collect-E">
<sysoid>.1.100.1.3</sysoid>
<collect>
<includeGroup>test-group-5</includeGroup>
</collect>
</systemDef>
<systemDef name="Collect-F">
<sysoidMask>.1.100.1.</sysoidMask>
<collect>
<includeGroup>test-group-6</includeGroup>
</collect>
</systemDef>
</datacollection-group>
```
```xml=
<datacollection-group name="UniqueC">
<systemDef name="Collect-G">
<sysoidMask>.1.</sysoidMask>
<collect>
<includeGroup>test-group-7</includeGroup>
</collect>
</systemDef>
<systemDef name="Collect-H">
<sysoid>.1.100.3.1</sysoid>
<collect>
<includeGroup>test-group-8</includeGroup>
</collect>
</systemDef>
<systemDef name="Collect-I">
<sysoid>.1.100.1.1.2</sysoid>
<collect>
<includeGroup>test-group-9</includeGroup>
</collect>
</systemDef>
</datacollection-group>
```
# Test scenarios
a) Node A belongs to categories `CatA` and `CatB`, and it has a `sysObjectID` of `.1.100.1.1`
b) Node B belongs to category `CatB`, and it has a `sysObjectID` of `.1.100.1.2`
As mentioned, there will be two effective `snmp-collections` called `group1` and `group2`, as the SNMP service appears twice in `collectd-configuration.xml`, each of them matching a different set of nodes.
Because all the `systemDefs` have unique names, the `group1` will contain `UniqueA` plus `UniqueB`, meaning it would have: `Collect-A` through `Collect-F`. Similarly, `group2` would contain `Collect-D` through `Collect-I`. Regardless of the `sysoid` and `sysoidMasks` inside the `systemDef`, what matters at this level is the `systemDef` name.
## For node A
Because it matches two `collectd` packages for the SNMP service, The collector will use both collections (`group1` and `group2`). In other words, it will check `Collect-A` through `Collect-I`. Note that even if `UniqueB` is referenced twice, it will be included once.
Now, as the node's `sysObjectID` is `.1.100.1.1`, only the `systemDefs` `Collect-A`, `Collect-C`, `Collect-D`, `Collect-F` and `Collect-G` will be included as those are the only ones with a `sysoid` or `sysoidMask` that matches the `sysObjectID`.
However, it will add the `mibObj groups` in the order they appear. If one `systemDef` is referencing a group already included, it won't add it again (one more time, knowing the groups is done by checking their names).
Remember the idea is to extract the list of `systemDefs` that match the `sysObjectID`, to get the list of `mibObj groups`, to finally get the list of `OIDs` to retrieve via SNMP.
## For node B
Because it matches one `collectd` package for the SNMP service, the collector will use one collection (`group2`). In other words, it will check `Collect-D` through `Collect-I`.
Now, as the node's sysObjectID is `.1.100.1.2`, only the `systemDefs` `Collect-D`, `Collect-F` and `Collect-G` will be included (for the same reason as the other use case).