Discussion:
Avoiding the User-supplied Python expression error
thomas
2011-11-30 11:07:06 UTC
Permalink
thomas [http://community.zenoss.org/people/thomas] created the discussion

"Avoiding the User-supplied Python expression error"

To view the discussion, visit: http://community.zenoss.org/message/62915#62915

--------------------------------------------------------------
I have a mysql template that uses an gathered RRDValue to dynamically calculate the threshold, however sometimes (probably because the template fails to gather data) I get this error:

User-supplied Python expression (here.getRRDValue('CheckMySql_Max_connections') * 0.9) for maximum value caused error: ['CheckMySql_Threads_connected']

The threshold is defined as follows:

here.getRRDValue('CheckMySql_Max_connections') * 0.8

I would like to know if it is possible to make a threshold that still does this, but if the here.getRRDvalue fails, then default to ie. 100.

Regards
Thomas
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/62915#62915]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Shane Scott
2011-12-01 01:17:10 UTC
Permalink
Shane Scott [http://community.zenoss.org/people/hackman238] created the discussion

"Re: Avoiding the User-supplied Python expression error"

To view the discussion, visit: http://community.zenoss.org/message/62936#62936

--------------------------------------------------------------
Thomas:

You can make use of the or statement to do this:

(here.getRRDValue('CheckMySql_Max_connections') * 0.8 or 100)

Best,
--Shane (Hackman238)
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/62936#62936]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
James Stewart
2011-12-05 05:27:09 UTC
Permalink
James Stewart [http://community.zenoss.org/people/amorphic] created the discussion

"Re: Avoiding the User-supplied Python expression error"

To view the discussion, visit: http://community.zenoss.org/message/63035#63035

--------------------------------------------------------------
Hi Shane,

Sorry for hijacking the thread but I have been using something similar to monitor filesystems and also need to set defaults. As you know, components such as filesystems cannot be allocated custom properties and as it is impractical to set a separate custom property for the Critical, Warning and Error thresholds of each filesystem on a device, I have set 3 custom properties per device, like so:

cFilesystemCrititcal = '/|90 /boot|90 /home|80 /tmp|90 /var|90'
cFilesystemError = '/80 /boot|80 /home|60 /tmp|85 /var|85'
cFilesystemWarning = '/|70 /boot|90 /home|40 /tmp|80 /var|80'

I then parse these values in the relevant filesystem threshold definition, and use them to generate a filesystem threshold:

here.totalBlocks * float(here.device().getProperty('cFilesystemCritical').strip().split(here.name())[1].split()[0].split('|')[1]) / 100

This works very well, but as per the OP I'm unable to set defaults, which results in a 'User-supplied Python expression... caused error' for filesystems with no default set.

To set a default of 100, I tried using 'or 100' at the end of my threshold, but it didn't make any difference.

Is this 'or statement' something Zenoss processes internally, i.e. 'result of user-defined python expression' *or* <default_value>. Or is this just plain Python and I'm misunderstanding something?

Thanks,

James
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/63035#63035]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Shane Scott
2011-12-06 16:14:13 UTC
Permalink
Shane Scott [http://community.zenoss.org/people/hackman238] created the discussion

"Re: Avoiding the User-supplied Python expression error"

To view the discussion, visit: http://community.zenoss.org/message/63084#63084

--------------------------------------------------------------
James Stewart:

Does

(here.totalBlocks or 1) * (float(here.device().getProperty('cFilesystemCritical').strip().split(here.name())[1].split()[0].split('|')[1]) / 100 or 100)

work?

It'll ensure if totalBlocks is invalid a 1 is returned and if the cProperty is invalid it'll return 100.

--Shane (Hackman238
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/63084#63084]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
James Stewart
2011-12-07 04:24:16 UTC
Permalink
James Stewart [http://community.zenoss.org/people/amorphic] created the discussion

"Re: Avoiding the User-supplied Python expression error"

To view the discussion, visit: http://community.zenoss.org/message/63094#63094

--------------------------------------------------------------
Thanks for getting back to me Shane, but alas that didn't work.

Stripping back the code, this is where the error occurs:

here.device().getProperty('cFilesystemCritical').strip().split(here.name())[1]

It seems that the fundamental problem is that the result of the split() on a missing filesystem name is only 1 item long, so trying to access element [1] raises a Python IndexError.

I've cut down the threshold to just this and it still errors:


(here.device().getProperty('cFilesystemCritical').strip().split(here.name())[1].split()[0].split('|')[1]) or 100)

This leads me to believe that the 'or' clause is unable to recognise that an IndexError has been raised and thus use the default value?
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/63094#63094]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Shane Scott
2011-12-07 19:11:04 UTC
Permalink
Shane Scott [http://community.zenoss.org/people/hackman238] created the discussion

"Re: Avoiding the User-supplied Python expression error"

To view the discussion, visit: http://community.zenoss.org/message/63126#63126

--------------------------------------------------------------
James Stewart:

It looks that way. I'm not sure how to address that. What does the contents of cFilesystemCritical look like?

--Shane
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/63126#63126]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
James Stewart
2011-12-08 00:01:51 UTC
Permalink
James Stewart [http://community.zenoss.org/people/amorphic] created the discussion

"Re: Avoiding the User-supplied Python expression error"

To view the discussion, visit: http://community.zenoss.org/message/63134#63134

--------------------------------------------------------------
Ah that's a shame... I thought I might have a way to eliminate these errors from my zenhub.log!

For each server I have 3 Custom Properties, (each shown with examples):

cFilesystemCritical: '/|95 /boot|80 /home|95 /opt|95 /tmp|90 /var|90'
cFilesystemError: '/|90 /boot|70 /home|90 /opt|90 /tmp|80 /var|80'
cFilesystemWarning: '/|85 /boot|60 /home|95 /opt|95 /tmp|70 /var|70'

I had a requirement to be able to set a custom threshold for any filesystem on any server. Implementing this with local copies of the filesystem template would've unwieldy for so many servers/filesystems, so this is what I came up with.

Apart from the lack of defaults, it seems to work well...
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/63134#63134]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Shane Scott
2011-12-08 14:57:02 UTC
Permalink
Shane Scott [http://community.zenoss.org/people/hackman238] created the discussion

"Re: Avoiding the User-supplied Python expression error"

To view the discussion, visit: http://community.zenoss.org/message/63146#63146

--------------------------------------------------------------
James Stewart:

Does your cProperty have a default value set?

--Shane
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/63146#63146]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
James Stewart
2011-12-08 22:10:59 UTC
Permalink
James Stewart [http://community.zenoss.org/people/amorphic] created the discussion

"Re: Avoiding the User-supplied Python expression error"

To view the discussion, visit: http://community.zenoss.org/message/63142#63142

--------------------------------------------------------------
Yep, and the default works well. The problem is when a server has non-standard mount points.

For example, my default Critical threshold is: cFilesystemCritical: '/|95 /boot|80 /home|95 /opt|95 /tmp|90 /var|90'

But if some server has a mount point called '/mnt/somename' there is no value for this in the default string and the Python expression error is generated.

It's not a huge problem - when I see one of these I just add the filesystem in question to the threshold for that server and all is well. It's just a shame I can't set a default...
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/63142#63142]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Shane Scott
2011-12-09 01:36:29 UTC
Permalink
Shane Scott [http://community.zenoss.org/people/hackman238] created the discussion

"Re: Avoiding the User-supplied Python expression error"

To view the discussion, visit: http://community.zenoss.org/message/63163#63163

--------------------------------------------------------------
James:

I agree. It's an unsatisfying result that split isn't letting us use or. You could try doing a smiple re.search on the cProperty for here.name and if it returns false then use a default.

Very tricky problem.

--Shane
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/63163#63163]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
James Stewart
2011-12-09 02:20:54 UTC
Permalink
James Stewart [http://community.zenoss.org/people/amorphic] created the discussion

"Re: Avoiding the User-supplied Python expression error"

To view the discussion, visit: http://community.zenoss.org/message/63145#63145

--------------------------------------------------------------
Yeah, the trick is squeezing it all into a one-liner...;-)
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/63145#63145]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Loading...