= Write Naemon Log = We can write to naemon.log file by issue command {{{ #!sh 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 )''' {{{ #!C 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 {{{ #!sh 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 {{{ #!sh 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 } }}} == Log viewer == Ref [https://github.com/sevdokimov/log-viewer, here][[br]] We use this java v8 to run as web server on port 8111 and browse the log file and show on web page. File can be download from the web or in attach [attachement:log-viewer-1.0.1.zip file] file with in this page {{{ #!sh [krit@mini log-viewer-1.0.1]$ ./logviewer.sh }}}