Forum Discussion
irule proc with default values failing
Hi
I have a proc defined as
proc loggingNowStr { log_now_clock log_now_msec } {
set log_now_diff [expr { $log_now_msec - ( $log_now_clock * 1000 ) }]
incr log_now_clock [ expr { $log_now_diff / 1000 }]
set log_now_fract [expr { $log_now_diff % 1000 }]
set log_now_fract [format "%03d" $log_now_fract]
set log_now_start_time_str [clock format $log_now_clock -format "%Y-%m-%d %H:%M:%S.${log_now_fract}"]
return $log_now_start_time_str
}
strangely I can't call it from RULE_INIT event. not a biggie - but can somebody explain why.
If I change the rule to
proc loggingNowStr { {log_now_clock [clock seconds]} {log_now_msec [clock clicks -milliseconds]} } {
set log_now_diff [expr { $log_now_msec - ( $log_now_clock * 1000 ) }]
incr log_now_clock [ expr { $log_now_diff / 1000 }]
set log_now_fract [expr { $log_now_diff % 1000 }]
set log_now_fract [format "%03d" $log_now_fract]
set log_now_start_time_str [clock format $log_now_clock -format "%Y-%m-%d %H:%M:%S.${log_now_fract}"]
return $log_now_start_time_str
}
So a I am adding in default values - i presume they are called at the time
it fails with
<CLIENT_ACCEPTED> - proc loggingNowStr not found (line 44) invoked from within "call loggingNowStr $log_cca_clock $log_cca_msec "
<CLIENT_ACCEPTED> - proc loggingNowStr not found (line 44) invoked from within "call loggingNowStr "$log_cca_clock" "$log_cca_msec" "
Hi
when i try this
rule proc_lib {
proc loggingNowStr2 { {log_now_clock 0} {log_now_msec 0} } {
}}
i get this
01070151:3: Rule [/Common/YB_SOEv2_Platform_logging_v1.1] error: /Common/YB_SOEv2_Platform_logging_v1.1:53: error: [undefined procedure: rule][rule proc_lib {
proc loggingNowStr2 { {log_now_clock 0} {log_now_msec 0} } {
}
}]I have my proc outside rule proc_lib
why do you use rule proc_lib ?
I tried your code - started a new irule and got this error
01070151:3: Rule [/Common/test] error: /Common/test:1: error: [undefined procedure: rule][rule proc_lib {
proc loggingNowStr { {log_now_clock 123456789} {log_now_msec 78341239432} } {
set log_now_diff [expr { $log_now_msec - ( $log_now_clock * 1000 ) }]
incr log_now_clock [ expr { $log_now_diff / 1000 }]
set log_now_fract [expr { $log_now_diff % 1000 }]
set log_now_fract [format "%03d" $log_now_fract]
set log_now_start_time_str [clock format $log_now_clock -format "%Y-%m-%d %H:%M:%S.${log_now_fract}"]
return $log_now_start_time_str
}
}]
- JRahmAdmin
HI AlexS_yb , it looks like it doesn't like clock to provide default values there...got the same errors you did until I just tried a test pattern. RULE_INIT works just fine for me otherwise.
rule proc_lib { proc loggingNowStr { {log_now_clock 123456789} {log_now_msec 78341239432} } { set log_now_diff [expr { $log_now_msec - ( $log_now_clock * 1000 ) }] incr log_now_clock [ expr { $log_now_diff / 1000 }] set log_now_fract [expr { $log_now_diff % 1000 }] set log_now_fract [format "%03d" $log_now_fract] set log_now_start_time_str [clock format $log_now_clock -format "%Y-%m-%d %H:%M:%S.${log_now_fract}"] return $log_now_start_time_str } } rule init_proc_test { when RULE_INIT { set x [call proc_lib::loggingNowStr] set y [call proc_lib::loggingNowStr [clock clicks] [clock clicks -milliseconds]] log local0. "Default args: $x; Provided args: $y" } } ### RESULT ### Jul 28 00:06:29 ltm3.test.local info tmm1[20054]: Rule /Common/init_proc_test : Default args: 1972-06-25 12:27:19.432; Provided args: 2022-07-28 00:06:29.879
- AlexS_ybCirrocumulus
Hi
when i try this
rule proc_lib {
proc loggingNowStr2 { {log_now_clock 0} {log_now_msec 0} } {
}}
i get this
01070151:3: Rule [/Common/YB_SOEv2_Platform_logging_v1.1] error: /Common/YB_SOEv2_Platform_logging_v1.1:53: error: [undefined procedure: rule][rule proc_lib {
proc loggingNowStr2 { {log_now_clock 0} {log_now_msec 0} } {
}
}]I have my proc outside rule proc_lib
why do you use rule proc_lib ?
I tried your code - started a new irule and got this error
01070151:3: Rule [/Common/test] error: /Common/test:1: error: [undefined procedure: rule][rule proc_lib {
proc loggingNowStr { {log_now_clock 123456789} {log_now_msec 78341239432} } {
set log_now_diff [expr { $log_now_msec - ( $log_now_clock * 1000 ) }]
incr log_now_clock [ expr { $log_now_diff / 1000 }]
set log_now_fract [expr { $log_now_diff % 1000 }]
set log_now_fract [format "%03d" $log_now_fract]
set log_now_start_time_str [clock format $log_now_clock -format "%Y-%m-%d %H:%M:%S.${log_now_fract}"]
return $log_now_start_time_str
}
}]- JRahmAdmin
I centralize all my procedures together in a library iRule that I call proc_lib so they can be maintained / managed separately from the logic of individual iRules. I updated my example to show the two named iRule objects, proc_lib and init_proc_test. First I created your procedure (unchanged except for a static default value for each argument) in the proc_lib iRule and then I added the init_proc_test iRule, which generated the resulting log entry when I saved it due to the RULE_INIT event firing and calling that loggingNowStr procedure in the proc_lib iRule twice, the first time with defaults in use and the second time with clock command values sent as arguments.
- PeteWhiteEmployee
I've never seen the setting of procedure default values to be the output of a command. Probably better to code it so that you set default to be false and then check whether it is still false. If not, set it to the output of the command:
proc loggingNowStr { {log_now_clock 0} {log_now_msec 0} } { if { $log_now_clock == 0 } { set log_now_clock [clock seconds] } if { $log_now_msec == 0 } { set log_now_msec [clock clicks -milliseconds] } set log_now_diff [expr { $log_now_msec - ( $log_now_clock * 1000 ) }] incr log_now_clock [ expr { $log_now_diff / 1000 }] set log_now_fract [expr { $log_now_diff % 1000 }] set log_now_fract [format "%03d" $log_now_fract] set log_now_start_time_str [clock format $log_now_clock -format "%Y-%m-%d %H:%M:%S.${log_now_fract}"] return $log_now_start_time_str }
- AlexS_ybCirrocumulus
Yeah thats what I ended up doing
AlexS_yb - If your post was solved it would be helpful to the community if you selected *Accept As Solution* on the relevant reply (or replies). This helps future readers find answers more quickly and confirms the efforts of those who helped. Thanks for being part of our community.
- AlexS_ybCirrocumulus
Not sure it was solved - defintely confirmed
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com