TECHZEN Zenoss User Community ARCHIVE  

User-supplied Python expression ((here.speed or 1e9) / 8 * .90)

Subject: User-supplied Python expression ((here.speed or 1e9) / 8 * .90)
Author: Marcos Espinoza
Posted: 2021-05-27 17:17

Hi guys, hope to get some help here, I just start evaluating and using zenoss(newbie).

My goal was to get interface threshold accurate at 90% for 30Mbps firewall interface, so I changed the interfaces speed using zendmd script to 30 Mbps, cos' zenoss was detecting the interfaces speed at 10Mbps, and the threshold start activating at 90% of 10Mbps.

DEVICE = 'xxx.xxx.xxx.xxx'
INTERFACE = 'ethx'
SPEED10Mb = '100000000'
SPEED30Mb = '30000000'
SPEED100Mb = '100000000'
SPEED1Gb = '1000000000'
SPEED10Gb = '10000000000'
SPEED = SPEED30Mb

d = dmd.Devices.findDevice(DEVICE)
for dev in d.Devices.getSubDevices():
if dev == d:
value = d.getProperty(dev)
for interface in d.os.interfaces():
if interface.id.startswith(INTERFACE):
print interface.id
print interface.speed
interface.speed = (SPEED)
commit ()

I can see now the interfaces are correctly defined at 30Mbps:


but, after I changed the speed of the interfaces, i notice an error on zenoss event:


This error only affects the interfaces I manually changed, am I missing something here ?
Zenoss version: Zenoss.core (v6.3.2)

Any help will be much welcome

Marcos


------------------------------
Marcos Espinoza
------------------------------


Subject: RE: User-supplied Python expression ((here.speed or 1e9) / 8 * .90)
Author: Michael Rogers
Posted: 2021-05-27 19:46

Marcos,

I think the UI is lying to us a bit.

The code responsible for displaying interface speeds in the UI is correctly interpreting the interface speed and displaying "30.0Mb/s."  What your variable declarations inserted into your code, however, wasn't a number; it was a string.

As a demonstration, here's me declaring 3 different speed variables and then multiplying each one by 10:

In [1]: speed1 = 1000

In [2]: speed2 = 100000

In [3]: speed3 = '10000000'

In [4]: speed1 * 10
Out[4]: 10000

In [5]: speed2 * 10
Out[5]: 1000000

In [6]: speed3 * 10
Out[6]: '10000000100000001000000010000000100000001000000010000000100000001000000010000000'

Your threshold is attempting to divide a string instead of a number which Python doesn't appreciate.  You can run back through your zendmd code to reset the values, or you can alter your threshold expression to:

((int(here.speed) or 1e9) / 8 * .90)

I would recommend running back through the script over changing an out-of-box template.

I hope that helps!

------------------------------
Michael J. Rogers
Senior Instructor - Zenoss
Austin TX
------------------------------


< Previous
Zenoss 4,2,5 eventClass Mapping
  Next
Unable to predict storage availability" error="Post http://127.0.0.1:8888/api/pe ...
>