ASSIST: List PSTs and sizes

Working on learning some Python (it confuses the crap out of me not using brackets to designate blocks)…

Having issues getting this modified script to report back when used as a monitor. This works fine without the alert() and ran on the machines through the procedures. When trying to use it as a monitor to send an email to me it doesn’t work.

#Please enter valid path
import os
import winshell
path=os.path.expanduser ('~/Documents/Outlook Files/')
print path
if(os.path.exists(path)):
    print('path is valid')
    proceed=1
else:    
    print('Please provide right path')
    proceed=0
if proceed==1:
    try:
        result=os.listdir(path)
        print'Files are available'
        for i in result:
            alert(1)
            print i
            print os.path.getsize(path,i)
    except Exception as err:
        alert(0)
        print err
        print'Please provide valid path'
else:
    pass

and this is what I get… no tripping of the monitor

2017-07-12_14h00_22.jpg

Hi, @zabolyx we have corrected your script as below
currently, custom monitoring script will run as system user only so kindly provide the complete path to be monitored.

Please refer the below script for your script request for custom monitoring script -(ASSIST: List PSTs and sizes) and let ur know your feedback.
Refer the attached JSON file.

NOTE:
Give your path where fin=r’C:\Users\ronalodo\Documents\Outlook Files’ in the below script.

FOR EXAMPLE: fin=r’(your path)’

import os 
import sys
import getpass
import socket
import _winreg 
fin=r'C:\Users\ronalodo\Documents\Outlook Files'
print "USER NAME: "+getpass.getuser()
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
print "IP-ADDRESS : "+(s.getsockname()[0])
from time import gmtime, strftime
time=strftime("%Y-%m-%d %H:%M:%S", gmtime())
print '
'
def alert(arg):
    sys.stderr.write("%d%d%d" % (arg, arg, arg)) 


# Please use "alert(1)" to turn on the monitor(trigger an alert) 
# Please use "alert(0)" to turn off the monitor(disable an alert) 
# Please do not change above block and write your script below 
    #Please enter valid path
#Please enter valid path
import os
print fin
if os.path.exists(fin):
    print('path is valid')
    try:
        os.chdir(fin)
        result=os.listdir(fin)
        print'Files are available'
        for i in result:
            b=os.path.getsize(i)
            print i +'	'+ str(b)
        alert(1)   
    except Exception as err:
        
        print err
        print'Please provide valid path'
        alert(0)
else:    
    print('Please provide right path')
    alert(0)


def checkUAC():
    if 'PROGRAMW6432' in os.environ.keys():
        handle = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Policies\System", 0, _winreg.KEY_READ | _winreg.KEY_WOW64_64KEY)
        return (_winreg.QueryValueEx(handle, "EnableLUA")[0]) 
    else:
        key = getattr(_winreg, "HKEY_LOCAL_MACHINE")
        subkey = _winreg.OpenKey(key, "Software\Microsoft\Windows\CurrentVersion\Policies\System")
        return (_winreg.QueryValueEx(subkey, "EnableLUA")[0]) 

checkUAC() 

Sample output:

20170713-List-PSTs-and-sizes.json (2.55 KB)

I’m not seeing any place in here that seems to handle checking all users on a computer. Is that correct or am I missing it?

If it isn’t what would I need to do to get it to handle that?

HI @zabolyx, Please refer the below script, we have made changes for your request to get all users on a computer. and let us know your feedback.
Please refer the attached JSON file. .

import os
import sys
ad=os.popen('net user').read()
import re
reg=re.findall('-
(.*
(.*))
(.+)',ad)
st1=str(reg)
li=[]
for i in range(0,len(st1)-1):
    if st1[i]!=' ':
        li.append(st1[i])
        i=i+1
    else:
        if st1[i]==' ':
            i=i+1
            if st1[i]!=' ':
                li.append(' ')

x=''.join(li)
c=x.split(',')
c[0]
li=[]
fin_user=[]
st2=str(c[0])
fin=st2.split(' ')
for x in range(0,len(fin)-1):
    li.append(fin[x].strip('[(').strip("'").strip('\
').strip('""'))

fin_user=[i for i in li if not i in ['DefaultAccount', 'Guest']]
def alert(arg):
    sys.stderr.write("%d%d%d" % (arg, arg, arg))
def all_users(wrd):
    global ale
    ale=0
    
    wrd=str(wrd)+'\\'
    import sys
    import getpass
    import socket
    import _winreg
    fin=r'C:\Users\%sDocuments\Outlook Files'%wrd
    print "USER NAME: "+getpass.getuser()
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect(("8.8.8.8", 80))
    print "IP-ADDRESS : "+(s.getsockname()[0])
    from time import gmtime, strftime
    time=strftime("%Y-%m-%d %H:%M:%S", gmtime())
    print '
'

    import os
    print fin
    if os.path.exists(fin):
        print('path is valid')
        try:
            os.chdir(fin)
            result=os.listdir(fin)
            print'Files are available'
            for i in result:
                b=os.path.getsize(i)
                print i +'	'+ str(b)
            ale=ale+1
              
        except Exception as err:
            print err
            print'Please provide valid path'
            
            
    else:    
        print('Please provide right path')
for wrd in fin_user:
    all_users(wrd)

if ale>0:
    alert(1)
else:
    alert(0)

20170714-List-PSTs-and-sizes.json (2.65 KB)

Good info to know. Currently testing the script. Thank you. Hope I can contribute better and more functional code as I learn.