Ask questions. Get answers. Find technical product solutions from passionate experts in the NXLog community.
file_remove with a variable
Thomas created
Dear Community
i have a output module in a file. Which creates a folder named with incomer IP Address. In this folder will be a file named Syslog+time+.log. This file is created every hour new. Thats works very good. Every new syslog sender is creating a new filder with its own IP address
Abstarct
C:\Program Files (x86)\nxlog\data<IP Address>\Syslog-.log
Reality
C:\Program Files (x86)\nxlog\data\123.123.123.123\Syslog-2018-23-01.log
C:\Program Files (x86)\nxlog\data\123.123.123.123\Syslog-2018-23-02.log
and so on
a another folder
C:\Program Files (x86)\nxlog\data\124.124.124.124\Syslog-2018-23-01.log
Code:
Module om_file
File $MessageSourceAddress+"/Syslog-"+ strftime(now(),"%Y-%m-%d-%H") + ".log"
CreateDir TRUE
up to this stage everything works.
Now I want create a deletion process of the files which are older than a particular time.
I try to use file_remove function but it is not working for me.
I try to get the IP folder name with $MessageSourceAddress. Therefore i create a variable (test). This variable should carry the foldername (123.123.123.123).
with
Exec {if not defined get_var('test') {create_var('test');} set_var('test',$MessageSourceAddress);}
Now I try to request the variable back in the file_remove function:
Exec file_remove('C:\Program Files (x86)\nxlog\data\+ 'get_var('test')'\*.log', (now()));
I always get this error
2018-01-23 14:20:20 WARNING stopping nxlog service
2018-01-23 14:20:20 WARNING nxlog received a termination request signal, exiting...
2018-01-23 14:20:22 ERROR Couldn't parse Exec block at C:\Program Files (x86)\nxlog\conf\nxlog.conf:96; couldn't parse statement at line 96, character 72 in C:\Program Files (x86)\nxlog\conf\nxlog.conf; syntax error, unexpected TOKEN_FUNCPROC, expecting )
2018-01-23 14:20:22 ERROR module 'file2' has configuration errors, not adding to route '1' at C:\Program Files (x86)\nxlog\conf\nxlog.conf:130
2018-01-23 14:20:22 WARNING not starting unused module eventlog
whole output module
Module om_file
File $MessageSourceAddress+"/Syslog-"+ strftime(now(),"%Y-%m-%d-%H") + ".log"
CreateDir TRUE
##Variable create
Exec {if not defined get_var('test') {create_var('test');} set_var('test',$MessageSourceAddress);}
## deltet old files
Exec file_remove('C:\\Program Files (x86)\\nxlog\\data\\+ 'get_var('test')'\\*.log', (now()));
Exec to_syslog_ietf();
Thomas created