TECHZEN Zenoss User Community ARCHIVE  

PythonCollector try to access the components with config.datasources (dsplugin.p ...

Subject: PythonCollector try to access the components with config.datasources (dsplugin.py)
Author: Daniel Vogel
Posted: 2019-05-13 10:29

Hello

I do not understand how I can access the components with dsplugin.py.
My dsplugin.py generate None. I want to have the Names components to update the status with ObjectMap.
Everything works fine if I enter the name directly ('id': 'zpool0').

data['maps'].append(
ObjectMap({
'relname': 'testPackPoolInfos',
'modname': 'ZenPacks.ABC.TestPack.TestPackPoolInfo',
'id': 'zpool0',
'pool2': 'Test von Daniel'
}))




The snmp modeler plugin PoolInfo.py:
...
def process(self, device, results, log):
zfs_pool = results[1].get('poolTable', {})

rm = self.relMap()
for snmpindex, row in zfs_pool.items():
name = row.get('zfsPoolName')
...

The dsplugin.py:
...
class Alerts(PythonDataSourcePlugin):

@classmethod
def config_key(cls, datasource, context):
return (
context.device().id,
datasource.getCycleTime(context),
context.id,
'testpack-alerts'
)
...
@inlineCallbacks
def collect(self, config):
data = self.new_data()

ds = config.datasources[0]
for k,v in ds.__dict__.items():
log.debug('ds k is %s and v is %s ' % (k,v))
...

Result:
2019-05-13 13:55:45,507 DEBUG zen.TestPack: ds k is cycletime and v is 300
2019-05-13 13:55:45,507 DEBUG zen.TestPack: ds k is severity and v is 3
2019-05-13 13:55:45,507 DEBUG zen.TestPack: ds k is component and v is None
2019-05-13 13:55:45,507 DEBUG zen.TestPack: ds k is manageIp and v is 192.168.11.63
2019-05-13 13:55:45,508 DEBUG zen.TestPack: ds k is points and v is []
2019-05-13 13:55:45,508 DEBUG zen.TestPack: ds k is config_key and v is ('192.168.11.63', 300, '192.168.11.63', 'testpack-alerts')
2019-05-13 13:55:45,508 DEBUG zen.TestPack: ds k is datasource and v is alerts
2019-05-13 13:55:45,508 DEBUG zen.TestPack: ds k is template and v is PoolInfo
2019-05-13 13:55:45,508 DEBUG zen.TestPack: ds k is device and v is 192.168.11.63
2019-05-13 13:55:45,508 DEBUG zen.TestPack: ds k is params and v is {}
2019-05-13 13:55:45,508 DEBUG zen.TestPack: ds k is eventClass and v is /Scout/zfsSum
2019-05-13 13:55:45,508 DEBUG zen.TestPack: ds k is plugin_classname and v is ZenPacks.ABC.TestPack.dsplugins.Alerts
2019-05-13 13:55:45,508 DEBUG zen.TestPack: ds k is eventKey and v is


Thank you in advance,
Daniel

------------------------------
Daniel Vogel
IT Infrastructure Architect
ABC Systems AG
Schlieren
------------------------------


Subject: RE: PythonCollector try to access the components with config.datasources (dsplugin.py)
Author: Laurent Hemeryck
Posted: 2019-05-14 03:52

Hello Daniel, 

Why this :
for k,v in ds.__dict__.items():

Please try with:
for k,v in ds.items():

If you are investigating how it works, start at a highe level and display the full content of the variable ds. 
Ouf of my head, I would say it's very possible that 'component' is an object. If you want to get the name, you will find it in "component.name". 

Cheers, 

Laurent


------------------------------
Laurent Hemeryck
Monitoring Engineer
FedNot
------------------------------

Subject: RE: PythonCollector try to access the components with config.datasources (dsplugin.py)
Author: Patrick McMahon
Posted: 2019-05-14 07:50

Double check that the template/datasource is on the component and not on the device
I would have expected context.id to be zpool0 instead of '192.168.11.63' in the config_key
config_key and v is ('192.168.11.63', 300, '192.168.11.63', 'testpack-alerts')

-Patrick

------------------------------
Patrick McMahon
Sr. Security and Compliance Specialist
Zenoss
------------------------------


Subject: RE: PythonCollector try to access the components with config.datasources (dsplugin.py)
Author: Daniel Vogel
Posted: 2019-05-14 10:27

Hello Patrick,

Yes you are right. Wow I defined a new template related to the component label in zenpack.yaml.

Now I got the component:
2019-05-14 13:39:09,710 DEBUG zen.TestPack: ds k is cycletime and v is 300
2019-05-14 13:39:09,710 DEBUG zen.TestPack: ds k is severity and v is 3
2019-05-14 13:39:09,710 DEBUG zen.TestPack: ds k is component and v is zpool0
2019-05-14 13:39:09,710 DEBUG zen.TestPack: ds k is manageIp and v is 192.168.11.63
2019-05-14 13:39:09,710 DEBUG zen.TestPack: ds k is points and v is []
2019-05-14 13:39:09,710 DEBUG zen.TestPack: ds k is config_key and v is ('192.168.11.63', 300, 'zpool0', 'testpack-alerts')
2019-05-14 13:39:09,710 DEBUG zen.TestPack: ds k is datasource and v is alerts
2019-05-14 13:39:09,710 DEBUG zen.TestPack: ds k is template and v is ZFSPoolInfo
2019-05-14 13:39:09,711 DEBUG zen.TestPack: ds k is device and v is 192.168.11.63
2019-05-14 13:39:09,711 DEBUG zen.TestPack: ds k is params and v is {}
2019-05-14 13:39:09,711 DEBUG zen.TestPack: ds k is eventClass and v is /Scout/zfsSum
2019-05-14 13:39:09,711 DEBUG zen.TestPack: ds k is plugin_classname and v is ZenPacks.ABC.TestPack.dsplugins.Alerts
2019-05-14 13:39:09,711 DEBUG zen.TestPack: ds k is eventKey and v is

Many thanks for your help,
Cheers Daniel


------------------------------
Daniel Vogel
IT Infrastructure Architect
ABC Systems AG
Schlieren
------------------------------


< Previous
ZenPackLib - compopnent guid display - remove defaulted Name column
  Next
Zenoss 6.2.1 Support for Old ZenPacks
>