Version 3 (modified by 3 years ago) (diff) | ,
---|
Write Naemon Log
We can write to naemon.log file by issue command
OMD[monitor@501264b41d2d]:~/var/naemon$ pwd /omd/sites/monitor/var/naemon OMD[monitor@501264b41d2d]:~/var/naemon$ echo "[$(date +%s)] User Activity msg TEST log" >> naemon.log
Linux command date +%s will print time in current time since Epoch 1970
In C program, we can implement this function with bash shell via system( bash cmd )
int writeLogFile( char *msg ) { char str_msg[1024]; sprintf( str_msg, "echo \"[%d] User Activity %s \" >> /omd/sites/monitor/var/naemon/naemon.log",(int)time(NULL), msg); printf(str_msg); system(str_msg); return 0; }
logrotate
we can config naemon.log to rotate as following
OMD[monitor@906094f86a76]:~/etc/logrotate.d$ more /omd/sites/monitor/etc/logrotate.d/naemon /omd/sites/monitor/var/naemon/naemon.log { daily rotate 7 nocompress olddir /omd/sites/monitor/var/naemon/archive dateext dateformat -%Y%m%d missingok notifempty postrotate [ -f /omd/sites/monitor/tmp/lock/naemon.lock ] && kill -s USR1 `cat /omd/sites/monitor/tmp/lock/naemon.lock` endscript create 0664 monitor monitor } /omd/sites/monitor/var/naemon/livestatus.log { missingok rotate 0 compress delaycompress notifempty create 640 monitor monitor }
A file thruk.log was an activity user log. We can logrotate as following
OMD[monitor@906094f86a76]:~/etc/logrotate.d$ more /omd/sites/monitor/etc/logrotate.d/thruk /omd/sites/monitor/var/log/thruk.log { daily rotate 3 nocompress olddir /omd/sites/monitor/var/log/archive dateext dateformat -%Y%m%d missingok notifempty create 660 monitor monitor } /omd/sites/monitor/var/thruk/cron.log { missingok rotate 0 compress delaycompress notifempty create 660 monitor monitor }
Attachments (2)
- log-viewer-1.0.1.zip (12.2 MB) - added by 3 years ago.
- log-viewer-1.0.1.tar.gz (1.2 MB) - added by 3 years ago.
Download all attachments as: .zip