Garin

So you've been asked by support to turn the log level up to 5 and send the logs ....

Discussion created by Garin on Oct 25, 2014
Latest reply on Nov 6, 2014 by StefanS

So, on my central hub, if I turn my log level to 3 and my logfile size to 10M, it rolls every 90 seconds. Too much going on to even entertain the idea of catching the logs while the system is running. Not enough time. And log level 5 is laughable - thankfully the drives on the central hub system saturate and slow down that log level generation rate.

 

The approach the probes have already is to rename the old file with an underscore which in my situation gives me another 90 seconds to maybe catch the event before that underscored log files goes away.

 

So, I put together the following LUA script to take care of the inability of a human to respond fast enough. Instead of the underscore approach, it tacks on a timestamp instead. And because this then has the possibility of creating an unlimited number of files, the script also implements a way of scanning for old files and removing them if older than 24 hours.

 

from_file_path = "C:\\Program Files (x86)\\Nimsoft\\hub\\" file1 = "_hub.log" to_file_path = from_file_path ts = timestamp.now() print(ts)  file.rename (from_file_path..file1,to_file_path..file1.."-"..ts..".sav")  for dir in io.popen([[dir "C:\Program Files (x86)\\Nimsoft\\hub\\_hub*.sav" /b /a-d]]):lines()  do     fullfile = "C:\\Program Files (x86)\\Nimsoft\\hub\\" .. dir    print(fullfile)     foo=file.stat(fullfile )    age=timestamp.diff(foo.mtime, "h", ts)    print("Age in hours is " .. age)    if ( age >= 24) then       print("Deleting " .. fullfile .. " due to its age")       file.delete (fullfile )    end     end

 It's not the prettiest script and almost none of it is mine but it does demonstrate the power of Google search and how one can cobble LUA examples together into something useful.

 

As an aside, the thing that I found the coolest was the following structure:

for dir in io.popen([[dir "C:\Program Files (x86)\\Nimsoft\\hub\\_hub*.sav" /b /a-d]]):lines()  do  .........  end

 for processing the output of OS commands without using intermediary files or other approaches.

 

Anyway, the idea is that then this script is run by dirscan:

 

   <SaveHubLogs>       active = yes       name = SaveHubLogs       description =        schedules =        directory = C:\Program Files (x86)\Nimsoft\hub       pattern = _hub.log       user =        password =        age_of_oldest = no       age_check_all = no       check_dir = yes       exclude_directory_pattern =        dir_age_check = no       recurse_dirs = no       qos_dir_exists = no       qos_number = no       qos_space = yes       qos_age = no       qos_response_time = no       number_command = "C:\Program Files (x86)\Nimsoft\sdk\nsa\nsa.exe" "C:\Program Files (x86)\Nimsoft\probes\service\nas\scripts\Garin\SaveHubLog"       file_size_type = individual       response_time_type = individual       <number_condition>          type = eq       </number_condition>       <age_condition>          unit = minutes          usercreationtime = No       </age_condition>       <space_condition>          unit = Mb       </space_condition>       <space_condition_delta>          unit = Mb       </space_condition_delta>       <file_size_condition>          unit = Kb       </file_size_condition>       <response_time_condition>          unit = milliseconds       </response_time_condition>       <message>          file_number_alarm = FileNumberAlarm          file_age_alarm = FileAgeAlarm          file_size_alarm = FileSizeAlarm          file_space_alarm = FileSpaceAlarm          file_delta_space_alarm = FileDeltaSpaceAlarm          response_time_alarm = ResponseTimeAlarm          directory_check_alarm = DirectoryCheckAlarm          file_error = FileError          dir_age_alarm = DirAge       </message>    </SaveHubLogs>

 

Whenever it sees the _hub.log file in the directory (expect number_condition equal to 0) it runs the script which renames the _hub.log file and so returning the count of _hub.log to zero.

 

You also need the Nas Script Agent installed wherever you intend to run this because that provides the LUA interpreter.

 

Enjoy and hopefully this is useful to someone.

 

And do note that this script deletes files and that there's always the possibility that it might misbehave in your environment and do something unintended. Test it on something safe before letting it lose.

 

-Garin

Outcomes