As with most of my python programs so far, this was inspired by a real need I had with my day job. We manage our clients networks utilizing Labtech’s RMM. Part of this is patch management. One of our clients needed some type of monthly report showing what patches got installed. Unfortunately, there isn’t a great canned report in Labtech to show this.

Labtech uses Crystal Reports, so I’m sure I could make a report to display this. The problem is two fold with doing it this way. One, I don’t know Crystal Reports, and two, Crystal Reports is as fast as a 28800 modem (how did we survive those?).

Since I’m learning Python and haven’t done anything with database access yet, I figured this would be the perfect place to start.

To talk to the MySQL database, I’m using mysql.connector. Here’s the run down of what this script does.

First, I wanted the ability to store the login information for the database, so I used code I wrote in the past to encrypt this into a file.  I put this code into a separate file called encryptconfig.py, which I import into the ltpaches.py file.

Also, I wanted to play around with the argparser module, so I used that to create all the command line parameters. It definitely makes it a lot simpler than the manual way I’ve done this in the past.

One last thing of note. You’ll notice the get patches function looks a little cumbersome. The reason is a record isn’t based on a patch. It’s based on an install of patches. That can be 1 patch or 100 patches. The record is one record either way. What I had to do was split the field that shows the patches installed and make each one it’s own record in the list. I also had to exclude the line that says “Updates require a reboot”.

Once I got this working, I simply ran the script with the -sl parameter to save the login details to a file. Then I created a scheduled task to run it with the “-ul passphrase” parameter.

Here’s the code from ltpatches.py.

 

Here’s the encryption.py code.

 

 

 

 

Author
profilepicJason Vanzin is the CEO at Vanzin Consulting Corp. He has over 15 years of IT experience and lives in Pittsburgh, PA. He blogs on topics related to Business Continuity, Python programming, and technology in general.

2 Comments

  1. Michael Bratton says:

    What are your thoughts on creating a similar report for third party app updates/installs based on Ninite’s integration?
    I’ve used both Ninite Pro and LabTech for quite some time but I would love to have a report like yours above that included both Windows and third party apps patching performed by our automation.

    • Jason Vanzin says:

      Michael,

      It’s something I definitely have considered, especially when I saw how much Labtech wanted for the third party update add-in from AppCare. Ninite is much cheaper. The reason I didn’t do anything with it yet is I don’t know all the logging information that Ninite does. It would have to save the logging information into the Labtech database, and then you could pull it out with a script like this. When I was looking at it, I wasn’t thinking of a report like this, but I wanted to write a script that would scan the log file and find any errors which would then generate tickets.

      Let me know how you are monitoring Ninite installs, and maybe I can point you in the right direction or help you make something. While I’m not currently doing anything with Ninite, it’s on my list of apps I want to write (an ever growing list).

      Jason

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: