====== Log Status Values to the Systemlog ======
For various purposes you can use the status data from our system and log it directly into the system log.
This Way you don't have to worry about file transwers and file rotating as this is all done by the system log deamon.
The log data can be downloaded easily via the techsupport function.
===== Script Summary =====
The script will take a mode parameter as the first argument. You can define to log in a single mode, and trigger the log externaly via a SDK trigger (Parameter: single). Instead of "single" you can define a periodicly logging by setting a intervall in seconds.
All the further Parameters which will be logged. This could be something like:
SYSTEM_TIME GNSS1_LONGITUDE GNSS1_LATITUDE MOBILE1_NETWORK MOBILE1_SIGNAL WAN_HOTLINK
Example:
Single Log with 5 Parameter:
single SYSTEM_TIME GNSS1_LONGITUDE GNSS1_LATITUDE MOBILE1_NETWORK MOBILE1_SIGNAL
Log every 15 seconds with 5 Parameters
15 SYSTEM_TIME GNSS1_LONGITUDE GNSS1_LATITUDE MOBILE1_NETWORK MOBILE1_SIGNAL
===== Installation of the Script =====
Detailed step by step instructions how to install a sdk script can be found [[sdk:testing-the-sms-send-script|on this wiki page]]
Please use the script with these parameters:
Scriptparameter: First parameter is the logging mode. all other Parameters are the status fields you like to log.
Trigger: in single mode use a event you want to log, or a perdiocle event every XXmin.
Trigger: in periodicle mode please use the event-based trigger" sdk-startup and the script will starting everytime the system boots up.
===== Check if the script is running =====
In the Systemlog under [[http://simulator.netmodule.com/logs.php.html|System->Troubleshooting->Network Debugging-> System Debugging]]
you will find the log output:
00 user.info sdkhost[2785]: testrun: SYSTEM_TIME:2016-09-14 04:29:54## GNSS1_LONGITUDE:8.572432## GNSS1_LATITUDE:50.134584## MOBILE1_NETWORK:n/a## MOBILE1_SIGNAL:MOBILE1_SIGNAL unknown## WAN_HOTLINK:n/a##
Sep 14 04:30:04 NB1600 user.info sdkhost[2785]: testrun: SYSTEM_TIME:2016-09-14 04:30:01## GNSS1_LONGITUDE:n/a## GNSS1_LATITUDE:n/a## MOBILE1_NETWORK:n/a## MOBILE1_SIGNAL:MOBILE1_SIGNAL unknown## WAN_HOTLINK:n/a##
Sep 14 04:30:10 NB1600 user.info sdkhost[2785]: testrun: SYSTEM_TIME:2016-09-14 04:30:09## GNSS1_LONGITUDE:n/a## GNSS1_LATITUDE:n/a## MOBILE1_NETWORK:n/a## MOBILE1_SIGNAL:MOBILE1_SIGNAL unknown## WAN_HOTLINK:n/a##
Sep 14 04:30:16 NB1600 user.info sdkhost[2785]: testrun: SYSTEM_TIME:2016-09-14 04:30:15## GNSS1_LONGITUDE:n/a## GNSS1_LATITUDE:n/a## MOBILE1_NETWORK:n/a## MOBILE1_SIGNAL:MOBILE1_SIGNAL unknown## WAN_HOTLINK:n/a##
Sep 14 04:30:22 NB1600 user.info sdkhost[2785]: testrun: SYSTEM_TIME:2016-09-14 04:30:21## GNSS1_LONGITUDE:n/a## GNSS1_LATITUDE:n/a## MOBILE1_NETWORK:n/a## MOBILE1_SIGNAL:MOBILE1_SIGNAL unknown## WAN_HOTLINK:n/a##
Sep 14 04:30:29 NB1600 user.info sdkhost[2785]: testrun: SYSTEM_TIME:2016-09-14 04:30:28## GNSS1_LONGITUDE:n/a## GNSS1_LATITUDE:n/a## MOBILE1_NETWORK:n/a## MOBILE1_SIGNAL:MOBILE1_SIGNAL unknown## WAN_HOTLINK:n/a##
Sep 14 04:30:37 NB1600 user.info sdkhost[2785]: testrun: SYSTEM_TIME:2016-09-14 04:30:35## GNSS1_LONGITUDE:n/a## GNSS1_LATITUDE:n/a## MOBILE1_NETWORK:n/a## MOBILE1_SIGNAL:MOBILE1_SIGNAL unknown## WAN_HOTLINK:n/a##
Sep 14 04:30:44 NB1600 user.info sdkhost[2785]: testrun: SYSTEM_TIME:2016-09-14 04:30:42## GNSS1_LONGITUDE:n/a## GNSS1_LATITUDE:n/a## MOBILE1_NETWORK:n/a## MOBILE1_SIGNAL:MOBILE1_SIGNAL unknown## WAN_HOTLINK:n/a##
Sep 14 04:30:49 NB1600 user.info sdkhost[2785]: testrun: SYSTEM_TIME:2016-09-14 04:30:49## GNSS1_LONGITUDE:n/a## GNSS1_LATITUDE:n/a## MOBILE1_NETWORK:n/a## MOBILE1_SIGNAL:MOBILE1_SIGNAL unknown## WAN_HOTLINK:n/a##
Sep 14 04:30:56 NB1600 user.info sdkhost[2785]: testrun: SYSTEM_TIME:2016-09-14 04:30:55## GNSS1_LONGITUDE:n/a## GNSS1_LATITUDE:n/a## MOBILE1_NETWORK:n/a## MOBILE1_SIGNAL:MOBILE1_SIGNAL unknown## WAN_HOTLINK:n/a##
===== The Script =====
/* DESC: A Script that can be used for a longtime logging of a NetModule Wireless Router.
* The upper part of the script is the logger template. The lower part is the real programm, where you describe the settings and workflow.
* Copyright (C) 2016 NetModule AG, Switzerland
*/
template logger
{
# give the constructor the array of fields to log
void logger(array logfields) {
this.fields = logfields;
}
int logNow(){
MAX_LINE_LEN=180;
//get current status output
sections = mkarray("system", "wan", "wwan", "wlan", "gnss", "lan", "openvpn", "ipsec", "dio", "license");
status = mkstruct();
for(i = 0; i < length(sections); i++) {
status=struct_merge(status, nb_status(sections[i]));
}
line = "";
for(i = 0; i < length(this.fields); i++) {
if(strlen(this.fields[i]) > 0 ) {
value = struct_get(status, this.fields[i]);
if(strlen(value) == 0) {
value = sprintf("%s unknown", this.fields[i]);
}
if(strlen(this.fields[i+1]) > 0 ) {
nextvalue = struct_get(status, this.fields[i+1]);
if(strlen(nextvalue) == 0) {
nextvalue = sprintf("%s unknown", this.fields[i+1]);
}
}
//line = sprintf('%s%s;', line,value);
line = sprintf("%s%s:%s## ", line, this.fields[i], value);
if (strlen(line)+strlen(sprintf("%s:%s##",this.fields[i+i],nextvalue))>MAX_LINE_LEN) {
nb_syslog(line);
line="";
}
}
}
if (strlen(line) > 0) nb_syslog(line);
return 0;
}
} // of template logger
if (argc < 3){
printf("usage: status_to_syslog.are [single|<1-n seconds>] ");
exit(1);
}
if (argv[1] == "single")
mode = 0;
else
mode = (int) argv[1];
elements = mkarray();
for (i = 2; i <= argc; i++) {
elements = array_merge(elements, argv[i]);
}
l = new logger(elements);
do {
l.logNow();
sleep(mode);
} while(mode);
exit(0);