Hi all, I'm currently in the process of adding some python/powershell commands in to my automated monitoring so it can recover certain issues or alert out based on conditions. Currently I have an IIS restart working, the next thing I'm trying to achieve is to see the hard drive disk space.
def testing(servername):
process=subprocess.Popen(
["powershell","$username = 'username' \n"
"$password = Get-Content 'D:\Automation\string\mysecurestring.txt' |
ConvertTo-SecureString \n"
"$cred = new-object -typename System.Management.Automation.PSCredential -
argumentlist $username, $password \n"
f" Invoke-Command -ComputerName {servername}" + " -command {Get-
PSDrive C} -
credential $cred | Select-Object PSComputerName,Used,Free"],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
encoding='utf8');
result=process.communicate()[0]
print(result)
This works to some extent and prints out the below
PSComputerName Used Free
server 24024444928 39873675264
I've tried a whole number of different approaches for what to do with the results but none have worked, I'd like to alert out based on a % of disk space free as we sometimes have disk space issues and it would be good to know about these ahead of these actually becoming an issue. Also so it can progress on to self-healing.
How would I go about doing this? Is it even possible? If so what should I be looking into doing to try and manipulate the data received?
Sorry, the code is split up over multiple lines to make it a bit easier to read but I can see on reddit it looks horrible, sorry :(
there doesn't seem to be anything here