Reports for you and For your customers

We have a very flexible Scripting capability. We want to write reports that can be used by You or your customers. We want to create these reports for you. We need your help in determining what “Theme” or what kind of reports you would want.

some examples:

-Employee Productivity Report: We can report on how actively the employees are using the computers given to them
-Computer Performance Monitor: We can report how well the computer resources are used etc.
-Software Usage Report: Reporting on all software usage, licensed or free…
and so on…

What kind of report do you want for us to create? Please respond.

We would really like a report that could be reviewed internally and sent to the customer that lists:

  • Completed scheduled procedures and the results (ie, check disk for errors, folder cleanup, install updates)
  • Computer performance monitor statistics
  • Hard drive disk health (total disk space, free disk space, total disk usage)
  • AV scan history and results (if AV installed)
  • Software usage

A report like this would be very helpful to us in managing our client endpoints and showing the benefits of having an MSP to the client.

Hopefully this can be developed. Thanks in advance!

I think just simply a report overview of hardware/software installed on each computer would be nice for management. Just having a more robust report builder would be awesome.

Hi @ntelogic , @maximillianx

Scripts for your requests are in progress. I will update here when completed. Thank you very much for your inputs.

Thanks,
Kannan

@mkannan Thank you!

Hi @maximillianx

I think just simply a report overview of hardware/software installed on each computer would be nice for management. Just having a more robust report builder would be awesome.

Please find requested script in the below reference.

https://forum.mspconsortium.com/foru…ventory-report

Thanks,
Purushothaman

Hi @ntelogic

  • Completed scheduled procedures and the results (ie, check disk for errors, folder cleanup, install updates)
  • Computer performance monitor statistics
  • Hard drive disk health (total disk space, free disk space, total disk usage)
  • AV scan history and results (if AV installed)
  • Software usage

I would like to get your feedback on this.

Please check with below report procedures for your requests.

https://forum.mspconsortium.com/forum/script-library/9144-get-itsm-monitoring-procedure-and-patch-management-logs-report

[URL=“https://forum.mspconsortium.com/forum/script-library/8909-view-and-send-email-of-threat-quarantine-and-containment-history-in-csv-format”]https://forum.mspconsortium.com/forum/script-library/9179-computer-hardware-and-software-inventory-report

https://forum.mspconsortium.com/forum/script-library/8909-view-and-send-email-of-threat-quarantine-and-containment-history-in-csv-format

Let us know if you have any missing reports.

Thank you @mkannan ! I’ll check them out over the weekend and let you know. Appreciate the support!

Hi @ntelogic

Please ignore my previous post where two forum reference link pointing to the same procedure. Refer required procedures in the below-mentioned URLs,

1.https://forum.mspconsortium.com/forum/script-library/9179-computer-hardware-and-software-inventory-report

  1. https://forum.mspconsortium.com/forum/script-library/9144-get-itsm-monitoring-procedure-and-patch-management-logs-report

3.https://forum.mspconsortium.com/forum/script-library/8909-view-and-send-email-of-threat-quarantine-and-containment-history-in-csv-format

Hi @mkannan these are great! Thank you very much!

Is there a simple way to format the results of the ITSM monitoring, procedure and patch management report?

Many thanks again!

Hi @ ntelogic

 Regarding your inquiry, we will be contacting you via email regarding your request for the formats.

Thanks @Jimmy !

Hi @ntelogic,

Please use the script to get Procedure Finished Success, Procedure Finished Fail, Installed Critical and Security Patches and Hard Disk Properties.

Note:
Please modify the variables as per your concern
emailto=[‘emailofreceiver@domain.com’]
emailfrom=‘emailofsender@domain.com’
password=‘password’
smtpserver=‘smtp.gmail.com
port=587

Sample Mail:

CSV Separator:
Use ‘|’ as a separator when you open the csv [output file]

msgbody='Hi,
Please find the attachment for the Computer Health Report in CSV file format.

Thank you.'
emailto=['emailofreceiver@domain.com']
emailfrom='emailofsender@domain.com'
password='password'
smtpserver='smtp.gmail.com'
port=587

import os
import re
import random

## get computer name
def computername():
    import os
    return os.environ['COMPUTERNAME']

## get ip address
def ipaddress():
    import socket
    return socket.gethostbyname(socket.gethostname())

## function to email with attachment
def emailreport(subject, emailto,emailfrom,fileToSend,password,smtpserver,port,msgbody):
    import smtplib
    import mimetypes
    from email.mime.multipart import MIMEMultipart
    from email import encoders
    from email.message import Message
    from email.mime.audio import MIMEAudio
    from email.mime.base import MIMEBase
    from email.mime.image import MIMEImage
    from email.mime.text import MIMEText
    import os
    msg = MIMEMultipart()
    msg["From"] = emailfrom
    msg["To"] = ",".join(emailto)
    msg["Subject"] = subject
    msg.preamble = subject
    body = MIMEText(msgbody)
    msg.attach(body)       
    with open(fileToSend, 'rb') as fp:
        record = MIMEBase('text', 'octet-stream')
        record.set_payload(fp.read())
        encoders.encode_base64(record)
        record.add_header('Content-Disposition', 'attachment', filename=os.path.basename(fileToSend))
        msg.attach(record)
    try:
        server = smtplib.SMTP(smtpserver,port)
        server.ehlo()
        server.starttls()
        server.login(emailfrom, password)
        server.sendmail(emailfrom, emailto, msg.as_string())
        server.quit()
        return "the email report has been sent to "+msg["To"]
    except Exception as e:
        return e

## function to convert any size of memory to bytes
def cb(string):
    b={'B':1, 'KB':1024, 'MB':1024*1024, 'GB':1024*1024*1024, 'TB':1024*1024*1024*1024, 'PB':1024*1024*1024*1024*1024}
    n,u=string.split()
    n=int(n)
    return int(n*b<u>)

## function to execute commands
def ecmd(CMD):
    import ctypes
    class disable_file_system_redirection:
        _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
        _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
        def __enter__(self):
            self.old_value = ctypes.c_long()
            self.success = self._disable(ctypes.byref(self.old_value))
        def __exit__(self, type, value, traceback):
            if self.success:
                self._revert(self.old_value)
    from subprocess import PIPE, Popen
    with disable_file_system_redirection():
        OBJ = Popen(CMD, shell = True, stdout = PIPE, stderr = PIPE)
    out, err = OBJ.communicate()
    return out.strip()


temp=str(random.randint(2017, 3000))+'.txt'
ptemp=str(random.randint(2017, 3000))+'p.txt'
if 'PROGRAMFILES(X86)' in os.environ.keys():
    pmlpath=os.path.join(os.environ['PROGRAMFILES(X86)'], 'COMODO\\Comodo ITSM\\pmlogs')
    prlpath=os.path.join(os.environ['PROGRAMFILES(X86)'], 'COMODO\\Comodo ITSM\\rmmlogs')
else:
    pmlpath=os.path.join(os.environ['PROGRAMFILES'], 'COMODO\\Comodo ITSM\\pmlogs')
    prlpath=os.path.join(os.environ['PROGRAMFILES'], 'COMODO\\Comodo ITSM\\rmmlogs')

with open(os.path.join(os.environ['TEMP'], 'report.csv'), 'wb') as c1:
    c1.write('Completed Maintenance Procedures
')

    ## procedure logs
    pfiles=os.listdir(prlpath)
    with open(os.path.join(os.environ['TEMP'], ptemp), 'wb') as fw:
        for file in pfiles:
            if file.startswith('Rmm_dll'):
                with open(os.path.join(prlpath,file), 'rb') as f:
                    while True:
                        line=f.readline()
                        if line:
                            if 'MsgProcedureRule/name: ' in line or 'status: PROCEDURE_FINISHED_SUCCESS' in line or 'status: PROCEDURE_FINISHED_FAIL' in line:
                                fw.write(line)
                        else:
                            break
    with open(os.path.join(os.environ['TEMP'], ptemp), 'rb') as fr:
        read=fr.read()
        item=''
        c1.write('|Finished Success
')
        for i in re.findall('MsgProcedureRule/name:.*
.*status:\sPROCEDURE_FINISHED_SUCCESS',read):
            ob=re.search('MsgProcedureRule/name:.*', i)
            t1=ob.group()
            if t1:
                if t1 not in item:
                    item+=t1
                    t1=t1.replace('MsgProcedureRule/name: ', '')
                    t1=t1.replace(' \r', '')
                    t1=t1.replace('|', '')
                    if not t1.startswith('\', \'\')'):
                        c1.write('||'+t1+'
')
        item1=''
        c1.write('|Finished Fail
')
        for j in re.findall('MsgProcedureRule/name:.*
.*status:\sPROCEDURE_FINISHED_FAIL',read):
            ob=re.search('MsgProcedureRule/name:.*', j)
            v1=ob.group()
            if v1:
                if v1 not in item1 and v1 not in item:
                    item1+=v1
                    v1=v1.replace('MsgProcedureRule/name: ', '')
                    v1=v1.replace(' \r', '')
                    v1=v1.replace('|', '')
                    if not v1.startswith('\', \'\')'):
                        c1.write('||'+v1+'
')

    ## remove the temp file of pmlogs
    os.remove(os.path.join(os.environ['TEMP'], ptemp))

    c1.write('

Completed Critical and Security Patches Installed
')
    ## patch management logs
    tempd=os.path.join(os.environ['temp'], 'templogs.txt')
    tempm=os.path.join(os.environ['temp'], 'tempm.txt')
    templ=os.path.join(os.environ['temp'], 'templ.txt')
    logfiles=[os.path.join(pmlpath, i) for i in os.listdir(pmlpath) if i.startswith('PatchInventoryCollector.log')]
    with open(tempd, 'wb') as w:        
        for i in logfiles:
            with open(i, 'rb') as r:
                 w.write(r.read())
    string=''
    with open(tempd) as r:
        while True:
            line=r.readline()
            if line:
                if 'Total Installed OS Patches:' in line or '] called' in line:
                    string+=line+'||'
            else:
                break
    i=0
    a,b='',''
    ls=string.split('||')
    while i+1<len(ls):
        if 'Total' in ls[i]:
            if 'called' in ls[i+1]:
                key=(ls[i].split()[1].split(':')[0], ls[i+1].split()[1].split(':')[0])
                if key[0]==key[1]:
                    a,b=key
                break
        i+=1

    if key:
        with open(tempm, 'wb')as w:
            with open(tempd) as r:
                ob=re.search('.*'+a+'.*(
.*)+.*'+b+'.*', r.read())
                w.write(ob.group())

    os.remove(tempd)

    with open(templ, 'w') as w:
        with open(tempm) as r:
            while True:
                line=r.readline()
                if line:
                    if 'Metadata' in line or 'Title:' in line or 'Patch Primary Category: "Security Updates"' in line or 'Patch Primary Category: "Critical Updates"' in line:
                        w.write(line)
                else:
                    break

    os.remove(tempm)

    with open(templ) as fr:
        for i in re.findall('Title:.*
.*Updates"',fr.read()):
            ob=re.search('".*\(.*\)"', i)
            t1=ob.group()
            if t1:
                c1.write('|'+t1[1:-1]+'
')

    os.remove(templ)

    c1.write('

Hard Disk Drive Health
')
    ## disk properties
    ld=[]
    for i in re.findall('Disk\s[0-9]+.*',ecmd('echo list disk |diskpart')):
        temp=[]
        ob2=re.search('Disk\s[0-9]+', i)
        t3=ob2.group()
        if t3:
            temp.append(t3)
        ob=re.search('[0-9]+\s(TB|GB|MB|KB|B)', i)
        t1=ob.group()
        if t1:
            temp.append(t1)
            a=cb(t1)
        ob1=re.search('[0-9]+\s(TB|GB|MB|KB|B)', i.replace(t1, ''))
        t2=ob1.group()
        if t2:
            temp.append(t2)
            b=cb(t2)
        c=((a-b)/a)*100
        c=str(c)+'%'
        temp.append(c)
        ld.append(temp)
    if ld:
        for i in ld:
            c1.write('|'+i[0]+'
||Total Space|'+i[1]+'
||Free Space|'+i[2]+'
||Disk % Utilized|'+i[3]+'

')
fileToSend=os.path.join(os.environ['TEMP'], 'report.csv')
subject=computername()+' | '+ipaddress()+' | CSV Health Report'
print emailreport(subject,emailto,emailfrom,fileToSend,password,smtpserver,port,msgbody)

## remove the csv file
os.remove(os.path.join(os.environ['TEMP'], 'report.csv'))

Script in Json:

Please let me know if you have any inconvenience.

Thank you.

20170413-Device-Health-Report.json (11.8 KB)

Hi @Purushothaman,

Thank-you for the script! We have tried it on a PC in our office and have experienced some errors…

First error: WindowsError: [Error 32] The process cannot access the file because it is being used by another process: ‘C:\Users\MKIOLB~1\AppData\Local\Temp\ emplogs.txt’

Second error: ITSM script log shows Finished success Connection unexpectedly closed. Nothing sent or received.

Lastly, on the end user machine, DISKPART starts to launch in a window, which triggers a User Account Control dialog box requring end user intervention. The DISKPART windows remains open until manually closed by the end user.

Thanks again!
Matt

Hi @ntelogic,

Thank you for contacting us, please let me have the script exactly what you used in your environment.

And the first error seems the file is already opened ‘C:\Users\MKIOLB~1\AppData\Local\Temp\ emplo gs.txt’ so it was being used by another process. Try the script once you have closed the file opened.

Other errors can be cleared once you send us the script. Maybe the script became incorrect for some variable changes.

Note, Please don’t share your email account and password. For them, use some dummy values.

And also share us some more information of machine configurations, OS and it’s version. Helpful to find the root cause of the issue. :slight_smile:

Thank you.

Greetings @Purushothaman ,

Attached is the script and the machine configuration.

Thank you for your assistance!

ComputerHealthReportScript.txt (8.49 KB)

SystemReport.txt (2.38 KB)

Hi @ntelogic,

Thank you for the detail and we will soon update the script and share it to you.

Hi @ntelogic,

As I have checked the script, the issue ‘Connection unexpectedly closed’ will be raised only when we give invalid email configuration. So I am sharing a script with sample g-mail account in the private message, there you can change the variable emailto=[‘youremailaddress@domain.com’] and then run the script. I hope that will be successful.

Note:
You don’t need to change anything else except the variable emailto

Thank you

Hi @Purushothaman ,

The script is working well now. One incorrect item however is the free disk space… it is not showing the correct free disk space amount which causes the Disk % utilized to be wrong.

One other request/question: Can the list of completed critical and security patches installed include what has been installed in the past 7 days only?

Many thanks again!
Matt

Hi @ntelogic,

I will check the code for the Disk % Utility and Change code to collect only the last 7 days installed patches.

And once more doubt to you, you would like to collect only procedures which are run for last 7 days on the endpoint?

Thank you.