= 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 [attachment:log-viewer-1.0.1.zip file] with in this page {{{ #!sh [krit@mini log-viewer-1.0.1]$ ./logviewer.sh }}} == Convert epoch time to human on Log file == ref [https://unix.stackexchange.com/questions/623046/convert-replace-time-from-epoch-milliseconds-to-human-readable-date-in-logfiles here] Example: file.log {{{ 1522693524403 entity1,sometext 1522693541466 entity2,sometext 1522693547273 entity1,sometext }}} Just use {{{ $ awk '{$1 = strftime("%F %T", substr($1,1,10))} 1' file.log 2018-04-02 21:25:24 entity1,sometext 2018-04-02 21:25:41 entity2,sometext 2018-04-02 21:25:47 entity1,sometext }}} With milliseconds {{{ $ awk '{$1 = strftime("%F %T", substr($1,1,10)) "." substr($1,11)} 1' file.log 2018-04-02 21:25:24.403 entity1,sometext 2018-04-02 21:25:41.466 entity2,sometext 2018-04-02 21:25:47.273 entity1,sometext }}}