Chrouwn
(Louis)
November 22, 2023, 11:51am
1
Hello Checkmk Community,
I am working on adding custom data to the host inventory and have encountered an issue. I executed the following command:
cmk -i --debug --detect-plugins=SNMP_inventory_extention [HOSTNAME]
on this script:
from .agent_based_api.v1 import (
contains,
exists,
OIDEnd,
register,
SNMPTree,
TableRow,
)
from .agent_based_api.v1.type_defs import (
InventoryResult,
)
register.snmp_section(
name="louis",
detect=startswith(".1.3.6.1.4.1.244.1.1.6", "[HOSTNAME]"),
fetch=SNMPTree(base='.1.3.6.1.4.1.244.1.1.6', oids=['2.0', '3.0']),
)
def inventory_extention(section) -> InventoryResult:
print("printing inventory...............................")
yield TableRow(
path=["result", "Nodes", "hardware", "Nodes", "system", "Attributes", "Pairs"],
key_columns={"serial_number": section["serial_number"]},
inventory_columns={
"serial_number": section["serial_number"],
"model_name": section["model_name"],
}
)
register.inventory_plugin(
name="louis",
inventory_function=inventory_extention,
)
and received this error:
deprecated plugins will be ignored in Checkmk version 2.2 (see werk #14084): SNMP_inventory_extention.py
Error in inventory plugin file /omd/sites/snmpTesting/local/share/check_mk/inventory/SNMP_inventory_extention.py: "'__name__' not in globals"
Does anyone have any insights on how to resolve this issue? Thank you in advance for your support.
gstolz
(Gerd Stolz)
November 22, 2023, 3:30pm
2
I think this might just be a path issue.
You’re using the current (since 2.0) API for the inventory, but your file is located in the legacy inventory plugin path.
Move the file from:
legacy: /omd/sites/snmpTesting/local/share/check_mk/inventory/SNMP_inventory_extention.py
current: /omd/sites/snmpTesting/local/lib/check_mk/plugins/agent_based/SNMP_inventory_extention.py
Chrouwn
(Louis)
November 22, 2023, 5:46pm
3
thanks for your help,
if i execute the command: cmk -i --debug --detect-plugins=SNMP_inventory_extention tsnw001.ts.fr.conti.de
it runs but i get no answer
and neither is the host inventory updated, is there maybe something missing in the script?
gstolz
(Gerd Stolz)
November 23, 2023, 9:25am
4
can you execute the same command but add “-vv” it will show you if the check is triggered and what data is requested/replied by snmp
Chrouwn
(Louis)
November 23, 2023, 10:53am
5
cmk -i --debug -vv --detect-plugins=SNMP_inventory_extention tsnw001.ts.fr.conti.de
Doing HW/SW inventory on: tsnw001.ts.fr.conti.de
tsnw001.ts.fr.conti.de:
+ INVENTORIZING
+ FETCHING DATA
Source: SourceType.HOST/FetcherType.SNMP
[cpu_tracking] Start [7fbb4b591610]
[SNMPFetcher] Fetch with cache settings: SNMPFileCache(tsnw001.ts.fr.conti.de, base_path=/omd/sites/snmpTesting/tmp/check_mk/data_source_cache/snmp, max_age=MaxAge(checking=0, discovery=120, inventory=120), disabled=False, use_outdated=False, simulation=False)
Not using cache (Mode Mode.FORCE_SECTIONS)
[SNMPFetcher] Execute data source
Not using cache (Mode Mode.FORCE_SECTIONS)
[cpu_tracking] Stop [7fbb4b591610 - Snapshot(process=posix.times_result(user=0.010000000000000009, system=0.0, children_user=0.0, children_system=0.0, elapsed=0.010000001639127731))]
Source: SourceType.HOST/FetcherType.PIGGYBACK
[cpu_tracking] Start [7fbb4b5914c0]
[PiggybackFetcher] Fetch with cache settings: NoCache(tsnw001.ts.fr.conti.de, base_path=/omd/sites/snmpTesting/tmp/check_mk/data_source_cache/piggyback, max_age=MaxAge(checking=0, discovery=120, inventory=120), disabled=True, use_outdated=False, simulation=False)
Not using cache (Cache usage disabled)
[PiggybackFetcher] Execute data source
No piggyback files for 'tsnw001.ts.fr.conti.de'. Skip processing.
No piggyback files for '10.219.145.210'. Skip processing.
Not using cache (Cache usage disabled)
[cpu_tracking] Stop [7fbb4b5914c0 - Snapshot(process=posix.times_result(user=0.0, system=0.0, children_user=0.0, children_system=0.0, elapsed=0.0))]
+ PARSE FETCHER RESULTS
Source: SourceType.HOST/FetcherType.SNMP
No persisted sections
-> Add sections: []
Source: SourceType.HOST/FetcherType.PIGGYBACK
No persisted sections
-> Add sections: []
Received no piggyback data
Received no piggyback data
+ EXECUTING INVENTORY PLUGINS
SUCCESS - Found 1 inventory entries
SUCCESS - Found 0 status entries
even though i get no piggyback data, i still get one inventory entry
gstolz
(Gerd Stolz)
November 23, 2023, 11:50am
6
oh - spotted the logical error:
your file is named “SNMP_inventory_extention” but your calling your check “louis” so it would have to be “–detect-plugins=louis”
Chrouwn
(Louis)
November 23, 2023, 12:52pm
7
thanks for your help, now the output looks like this:
+ INVENTORIZING
+ FETCHING DATA
Source: SourceType.HOST/FetcherType.SNMP
[cpu_tracking] Start [7f069f13b2e0]
[SNMPFetcher] Fetch with cache settings: SNMPFileCache(tsnw001.ts.fr.conti.de, base_path=/omd/sites/snmpTesting/tmp/check_mk/data_source_cache/snmp, max_age=MaxAge(checking=0, discovery=120, inventory=120), disabled=False, use_outdated=False, simulation=False)
Not using cache (Mode Mode.FORCE_SECTIONS)
[SNMPFetcher] Execute data source
louis: Fetching data (SNMP walk cache cleared)
Executing BULKWALK of ".1.3.6.1.4.1.244.1.1.6.2" on tsnw001.ts.fr.conti.de
.1.3.6.1.4.1.244.1.1.6.2.0 => [b'0080A3C30B4E'] 'OCTETSTR'
Executing BULKWALK of ".1.3.6.1.4.1.244.1.1.6.3" on tsnw001.ts.fr.conti.de
.1.3.6.1.4.1.244.1.1.6.3.0 => [b'8.8.0.0R6'] 'OCTETSTR'
Not using cache (Mode Mode.FORCE_SECTIONS)
[cpu_tracking] Stop [7f069f13b2e0 - Snapshot(process=posix.times_result(user=0.030000000000000027, system=0.009999999999999981, children_user=0.0, children_system=0.0, elapsed=0.14000000059604645))]
Source: SourceType.HOST/FetcherType.PIGGYBACK
[cpu_tracking] Start [7f069f13b8e0]
[PiggybackFetcher] Fetch with cache settings: NoCache(tsnw001.ts.fr.conti.de, base_path=/omd/sites/snmpTesting/tmp/check_mk/data_source_cache/piggyback, max_age=MaxAge(checking=0, discovery=120, inventory=120), disabled=True, use_outdated=False, simulation=False)
Not using cache (Cache usage disabled)
[PiggybackFetcher] Execute data source
No piggyback files for 'tsnw001.ts.fr.conti.de'. Skip processing.
No piggyback files for '10.219.145.210'. Skip processing.
Not using cache (Cache usage disabled)
[cpu_tracking] Stop [7f069f13b8e0 - Snapshot(process=posix.times_result(user=0.0, system=0.0, children_user=0.0, children_system=0.0, elapsed=0.0))]
+ PARSE FETCHER RESULTS
Source: SourceType.HOST/FetcherType.SNMP
No persisted sections
-> Add sections: ['louis']
Source: SourceType.HOST/FetcherType.PIGGYBACK
No persisted sections
-> Add sections: []
Received no piggyback data
Received no piggyback data
+ EXECUTING INVENTORY PLUGINS
louis: ok
louis: skipped (no data)
SUCCESS - Found 4 inventory entries
SUCCESS - Found 0 status entries
it seems to work but i splugin louis is still skipped, even though i receive the data
gstolz
(Gerd Stolz)
November 24, 2023, 8:21am
8
Hi,
louis: ok
louis: skipped (no data)
SUCCESS - Found 4 inventory entries
SUCCESS - Found 0 status entries
But before you only had 1 inventory entry. I rarely analyze these messages so precisely, so maybe the “louis: ok” is for your inventory and the “louis: skipped” is because there is no check function for your louis section?
You can check the inventory if the entries for model_name + serial_number are present?