first commit
This commit is contained in:
43
setup.py
Normal file
43
setup.py
Normal file
@@ -0,0 +1,43 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from setuphelpers import *
|
||||
import subprocess
|
||||
|
||||
hour_reboot = '18:00'
|
||||
day_reboot = 'SUN'
|
||||
|
||||
def install():
|
||||
pass
|
||||
|
||||
def check_reboot_pending(hostname):
|
||||
"""
|
||||
Fonction pour vérifier si un poste a un reboot en attente.
|
||||
|
||||
Args:
|
||||
hostname: Le nom d'hôte du poste à vérifier.
|
||||
|
||||
Returns:
|
||||
True si un reboot est en attente, False sinon.
|
||||
"""
|
||||
returncode = run('systeminfo | find "Restart"',accept_returncodes=[0, 1, 3010])
|
||||
|
||||
if returncode:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def audit():
|
||||
hostnames = ["localhost"]
|
||||
reboot_pending = check_reboot_pending(hostnames)
|
||||
print(reboot_pending)
|
||||
if reboot_pending is True:
|
||||
print(f"Le poste a un reboot en attente.")
|
||||
WAPT.write_audit_data_if_changed("Update Reboot", "Reboot Pending", reboot_pending)
|
||||
run(f'schtasks /create /sc weekly /st {hour_reboot} /RU "NT AUTHORITY\SYSTEM" /d {day_reboot} /tn "Reboot_Update" /tr "shutdown /r /t 0"')
|
||||
return "WARNING"
|
||||
else:
|
||||
print(f"Le poste n'a pas de reboot en attente.")
|
||||
WAPT.write_audit_data_if_changed("Update Reboot", "Reboot Pending", reboot_pending)
|
||||
if task_exists("Reboot_Update") is True:
|
||||
run('schtasks /delete /tn "Reboot_Update" /f')
|
||||
return "OK"
|
||||
|
||||
Reference in New Issue
Block a user