Script Error AttributeError: 'module' object has no attribute 'disk_usage'

Hi,

I’m trying to put together a very simple script to monitor and alert users their disk usage percentage if it goes below a certain amount. I don’t want to use the disk condition that’s already on the site as I need to add more text to the message. I’m not very good with python so any help would be grateful.

The script run’s fine on my own local machine, but when I try to use within Itarian, I get AttributeError: ‘module’ object has no attribute ‘disk_usage’ I am using ‘import shutil’

Any idea’s what’s going on here?

Regards

Hi @daz1971 ,

Can you please share the script which you were trying to run in ITarian?

Kind Regards,
PremJK

Hi,

Sure here’s the script, it’s very basic in terms of the calculating of the disk space, but it’s fine for our own needs. I’ve had to replace some hardcoded values of machine and user names with x’s but I think you should get an idea of what we are trying to achieve

Best Regards

import sys
import os
import re
import socket
import shutil
import math

mn = socket.gethostname()
total, used, free = shutil.disk_usage(“C:/”)
total=("%d" % (total // (230)))
used=("%d" % (used // (2
30)))
free=("%d" % (free // (2**30)))
c1 = int(free) / int(total)
c2=c1*100
c3 = math.trunc(c2)
p = 0
def alert(arg):
sys.stderr.write("%d%d%d" % (arg, arg, arg))

if c3 <= 34:
alert(1)
print()
if mn == ‘xxxxx_Laptop’:
print(“Trello Handle @xxxxx13”)
if mn == ‘xxxxx_Desktop’:
print(“Trello Handle @xxxxx7”)
if mn == ‘xxxxxx_Laptop’:
print(“Trello Handle @xxxxx2”)
if mn == ‘xxxx_Laptop’:
print(“Trello Handle @xxxxx4”)
if mn == ‘xxxx_Desktop’:
print(“Trello Handle @xxxxx4”)
if mn == ‘xxxxx_Laptop’:
print(“Trello Handle @xxxxx3”)
else:
pass
print()
print(“CRITICAL: Ransomware protection disabled on " + mn + " due to low disk space”)
print()
print(“CRITICAL: Windows Updates will not be Installed **”)
print()
print(“CRITICAL: Your SSD lifespan will dramatically reduce **”)
print()
print(“Please urgently free up disk space on your C: Drive (minimum 35%) to re-enable”)
print()
print(“Your Free Disk space is currently " + str(c3) + " Percent”)
p =1
else:
alert(0)

Hi @daz1971 ,

Thanks for providing the script, we have shared your script with our script developers.

Kind Regards,
PremJK

Hi PremJK,

thanks for the quick response and for submitting the script to your developers. Looking forward to hearing back from you on it.

Best Regards

Hi @daz1971 ,

Our script developers have modified the script which will work in our portal, please try this JSON file
diskusage script.json (3.5 KB)

Kind Regards,
PremJK

Hi PremJK,

Really Appreciate that, thank you and your script Devs very much for coming back with this.

Best Regards

Darren

1 Like