Score:0

Rsyslog expression with $programname is not working

ng flag

got this in my rsysconf:

    $template TemplateLog,"%msg%\n"   
    $template DynamicLog,"%msg%\n"                                                                                                                            
    $template DynamicFile,"/var/log/%PROGRAMNAME%.log"    
    if ($programname == "test") then {local3.=debug    -/var/log/path.log;TemplateLog}                                                                  
    local3.=debug    -?DynamicFile;DynamicLog                                                                                                                 
    & stop   

If I put away the if statement, it works well. But I need to make the if statement working. What is wrong about it? Thank you for advice.

I tried to change the == to contains as suggested in one of answers, this does not help.

Is $programname containing same info as %PROGRAMNAME% ? This could cause the problem, maybe...

So acording to answer, I have made this:

$template TemplateLog,"%msg%\n"   
$template DynamicLog,"%msg%\n"                                                                                                                            
$template DynamicFile,"/var/log/%PROGRAMNAME%.log"           
template(name="pname" type="string" string="%PROGRAMNAME%")                                                                                               
set $!xyz = exec_template("pname");     
if ($!xyz contains'test') then {local3.=debug    -/var/log/path.log;TemplateLog}
local3.=debug    -?DynamicFile;DynamicLog                                                                                                                 
& stop   

But unfortunately, this code is not working either. If I delete the if statement, the second DynamicFile is saved into test.log, so the value is correct.

Score:0
ng flag

You can always print the variable to see the output. I think is something related to syntax, please try using contains instead of ==.

You can assign it to a var using templates:

    $template DynamicLog,"%msg%\n"                                                                                                                            
    $template DynamicFile,"/var/log/%PROGRAMNAME%.log"    
    template(name="pname" type="string" string="%PROGRAMNAME%")
    set $!xyz = exec_template("pname");
    if ($!xyz contains 'test') then {local3.=debug    -/var/log/path.log;TemplateLog}                                                                 
    local3.=debug    -?DynamicFile;DynamicLog                                                                                                                 
    & stop```
ng flag
No, this is not helping. Im almost sure it is something with syntax, cant see it tho, as Im really not into this
ng flag
How do you print it tho?
Zhivko Zhelev avatar
ng flag
Ok, so ```$programname``` and ```%PROGRAMNAME%``` are not the same, you can't just use "programname" as var.
Zhivko Zhelev avatar
ng flag
So probably the ```if``` syntax is ok, but you can do it with template (I will edit my answer)
ng flag
Thanks ! I have adjusted the answer, so it is according to current state, but it still unfortunately doesnt work :(
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.