Reply

CSS Trigger-filter treat variables as numbers??

adomeit
Techie
Posts: 7
2153     0

Hi,

I think I'm stuck but it looks like when I try to compare numbers stored in variables for trigger-filters that CCS somehow won't do it and appears to treat everything as text.  I've tried to set the trigger variable type as int, string, and word and they all behave the same way.

 

Here's sort of an example just to give you an idea...I've tried all kinds of iterations of different types of variables and operators and every time, it seems like CCS is treating the values as a string and not a number.  If I use comparative operators like < and = in script filters they work but not inside action and trigger filters.  Am I just doing it wrong?

 

Trigger-Variables:

# set something so it will match two numbers

$firstnumber int

$secondnumber int

 

Trigger-Template:

[[$firstnumber]] [[$secondnumber]]

 

Trigger-Commands: { $firstnumber > $secondnumber }

SET: $someflag = "I'm big but just for today"

 

 

 

 

Re: CSS Trigger-filter treat variables as numbers??

Expert
Posts: 257
2154     0

What you surmised is correct.  To get the strings to be interpreted as integers so you can perform math or numeric comparisions, you need to use the EXPR command.  See the Network Automation CCS Scripting Guide.

Re: CSS Trigger-filter treat variables as numbers??

adomeit
Techie
Posts: 7
2154     0

Hi,

Here's where it ends up...I couldn't get expr: to work as part of a trigger-command filter so I ended up having to run the expression before the trigger-command, store the result and then process that result (as text) as part of the trigger-command filter.  

 

Trigger-Variables:

# set something so it will match two numbers

$firstnumber int

$secondnumber int

 

Trigger-Template:

# grab two numbers

[[$firstnumber]] [[$secondnumber]]

 

# $answer will boolean 0|1 based on result

EXPR: $answer = $firstnumber > $secondnumber

 

# Remember to treat the value as text!!

Trigger-Commands: { $answer like /0/ }

SET: $someflag = "First number is smaller"

 

# Remember to treat the value as text!!

Trigger-Commands: { $answer like /1/ }

SET: $someflag = "First number is bigger"

 

Showing results for 
Search instead for 
Do you mean 

Recommended for You