This Script is used to monitor the Squid Cache File Size and raise alert when the size exceeds 2.5 GB.
Note : Run as Custom Monitoring Script.
Run the script as custom monitoring
https://wiki.itarian.com/frontend/web/topic/how-to-use-custom-script-procedure-monitoring
You need to Run the Script auto-remediation alert on Run below procedure:(refer the below image)
Refer the below wiki link for Auto remediation alert Configurations:
https://wiki.itarian.com/frontend/web/topic/how-to-configure-alerts
Note:
Please Do not Use the Script as Normal Procedure
The below-mentioned script is Auto Remediation Procedure its Only for the above Custom monitoring script.
(Before running the custom monitoring you need to import below-mentioned auto-remediation procedure in normal procedure)
https://scripts.itarian.com/frontend/web/topic/script-to-delet
import os
import ctypes
import sys
def alert(arg):
sys.stderr.write("%d%d%d" % (arg, arg, arg))
def getfoldersize(path):
total_size = 0
spath = path
for path, dirs, files in os.walk(spath):
for f in files:
fp = os.path.join(path, f)
total_size += os.path.getsize(fp)
return str(total_size)
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)
Squid_Path = r"{0}\Squid_ITarian\var\cache".format(os.environ['systemdrive'])
if os.path.exists(Squid_Path):
print("Squid cache folder is present on the system")
filesize = getfoldersize(Squid_Path)
if int(filesize) > 2684354560:
print("The 2.5 GB quota for the Squid cache folder is exceeded")
print("The cache folder will be deleted")
alert(1)
else:
print("The 2.5 GB Squid quota for the cache folder is NOT exceeded")
alert(0)
else:
print("Squid cache folder is NOT present on the system !!!")
print("This procedure will stop")
alert(0)
Comments