Kaseya Community

Reading the most recent text file in a directory

  • I am working on using Kaseya to parse my backup software (Servosity 7) text logs to check for errors or warnings automatically. I am very new to Kaseya and I'm not sure how to have it parse a text file if I can't provide the specific file name. It is formatted as date and time as the name, which obviously changes daily, or multiple times a day if I run multiple backups for a client. 

    Any ideas on how to get the filename of the most recent file in a folder. It's for MAC clients if that makes a difference. 

    I'd also love help finding the directory name, because it's in a folder named for each backup set, which is different per machine, and I'd love to not have to set the directory manually on each machine.

  • Disclaimer, 0 experience with Servosity.

    To answer your direct question, I would probably write a script to do the parsing and find a way to alert on the output of the script. Potentially in a post-backup command launched from Servosity (if that exists). In Windows, I would have that script write to the Windows Event Logs and create a monitoring set in Kaseya for that. Since we use ConnectWise for ticketing, on a Mac I would probably just have the parsing script generate an e-mail to ConnectWise that creates a ticket. I haven't had a lot of luck with Kaseya's log file monitoring, probably because I haven't put the time in, but you might have better luck using a post-backup script to parse the actual logs and then output much simpler results to a static log file; then use Kaseya's log file monitoring to monitor that static file.

    A case that often gets overlooked is what happens when no backup runs. There isn't an error, so potentially no alert, but something is definitely wrong. Make sure your monitoring strategy takes this into account.

    A bit deeper into the question, I would take a step back and design a more reliable, standardized procedure for deployment so your folder names are predictable. For example, we wrote a lot of custom integration around StorageCraft. When we create jobs, it is all scripted so the job name has a format similar to 'KaseyaAgentName_Volume'. If we need to do any work on the backups, it is mostly done through scripts and those scripts know how to find the backup files because they are named consistently across the board. We have a post-backup script we built that sends job data back to us and then have nightly procedures scheduled to analyze the data and generate tickets based on failures, no new backups in X days, etc. Standardized procedures are key for scaling anything; if things are done the same everywhere, it is much easier to manage them.

    For finding directories, my first choice would be using a Servosity API to get the actual backup targets. Baring that, I would try to find where Servosity saves its configuration; you might get lucky and it could be just a text file somewhere. You could pull the backup targets from that. Another option would be setting the backup target as a custom field in Kaseya; this becomes available to Agent Procedures where you can do the parsing. Worst case find with -regex would work if the paths have at least some homogeneity between names. Hopefully you have a potential starting path if you are going to use find.

  • Thank you so much, you lead me in the right direction, and after much googling I was able to write a batch script to find the most recent backup log file across all folders, copy it to a static named directory, and rename it to "backup.txt".

    Now I can run that script periodically to update that backup.log file.

    The next thing I need to do is write a script to parse the text in that file, and return a notification and change client status if there is a line containing [warn] or [erro].

    Also it's super frustrating that I can't approve my own procedures, now I have to involve my customer every time I want to test a script.

    [edited by: sonofskywalker3 at 6:47 PM (GMT -8) on Jan 12, 2017]
  • ,

    You can toggle the AP signing function off if you want to bypass the requirement to approve procedures.  Navigate to System > Default Settings, select "Enable Agent Procedure Signing", click the Edit button (at the top of the page), and toggle the setting to "No."  This will disable the requirement for APs to be signed/approved.

    Note:  This setting is global to the server (On Prem) or tenant (SaaS).  This will affect all VSA users with access to create/edit Agent Procedures.