def login_account(): """ get login statistics (not really working) :return: """ # ac -p | sort -nr -k 2 ret, lines = system_exec("ac -p | sort -nr -k 2") logger.log("weekly", "login time statistics\n" + "\n".join(lines)) add_paragraph_with_lines("Login statistic", 3, lines=lines)
def main(dry_run: bool = False): """ main script execution :param dry_run: if the script should be run without system modification :return: """ # if check_certificates(): logger.log("autoSSLRenew", "Certificates Still valid") add_paragraph("SSL renewal", message="SSL certificates are still valid") return logger.log("autoSSLRenew", "Certificates due to renewal") ret, lines = system_exec("/usr/local/bin/certbot renew" + ["", " --dry-run"][dry_run]) if ret != 0: logger.log_error("autoSSLRenew", "certbot return code (" + str(ret) + ")") for line in lines: logger.log_error("autoSSLRenew", line) return if check_certificates() or dry_run: logger.log("autoSSLRenew", "SSL Certificates have been successfully renewed") add_paragraph( "SSL renewal", message="SSL Certificates have been successfully renewed") if dry_run: return ret, lines = system_exec("rcctl restart apache2") if ret == 0: return logger.log_error("autoSSLRenew", "Unable to restart web server after renewal") for line in lines: logger.log_error("autoSSLRenew", line) ret, lines = system_exec("rcctl restart smtpd") if ret == 0: return logger.log_error("autoSSLRenew", "Unable to restart mail server after renewal") for line in lines: logger.log_error("autoSSLRenew", line) else: logger.log_error( "autoSSLRenew", "SSL Certificates are still invalid after renew\n" + "\n".join(lines)) add_paragraph_with_lines( "SSL renewal", pre_message=["SSL Certificates are still invalid after renew"], lines=lines)
def newsyslog_forced(): """ monthly log rotate has to be forced :return: """ logger.log("monthly", "newsyslog forced") ret, lines = system_exec("/usr/bin/newsyslog -F") if len(lines) != 0: # il y a un probleme logger.log_error("monthly", "problem in newsyslog execution\n" + "\n".join(lines)) add_paragraph_with_lines( "newsyslog", pre_message=["problem in newsyslog execution"], lines=lines)
def locate_database(): """ update the locate database :return: """ # /usr/libexec/locate.updatedb logger.log("weekly", "Updating locate database") ret, lines = system_exec("/usr/libexec/locate.updatedb") if len(lines) != 0: # houston, we got a problem logger.log_error( "weekly", "problem in locate database update\n" + "\n".join(lines)) add_paragraph_with_lines( "locate_database", 3, pre_message=["Problems in locate database reconstruction"], lines=lines)
def whatis_database(): """ update the whatis database :return: """ # /usr/sbin/makewhatis logger.log("weekly", "whatis database update") ret, lines = system_exec("/usr/sbin/makewhatis") if len(lines) != 0: # il y a un probleme logger.log_error( "weekly", "problem in whatis database update\n" + "\n".join(lines)) add_paragraph_with_lines( "whatis_database", 3, pre_message=["problem in whatis database update"], lines=lines)
def check_packages(): """ check the package installation :return: """ # now check packages ret, lines = system_exec("pkg_check -xq") ok = True for line in lines: if "ok" not in line: ok = False break if not ok: # houston, we got a problem logger.log_error("weekly", "problem in packages\n" + "\n".join(lines)) add_paragraph_with_lines("check_packages", 3, pre_message=["problem in packages"], lines=lines)
def main(dry_run: bool = False): """ main script execution :param dry_run: if the script should be run without system modification :return: """ logger.log("daily", "runing daily procedure") # hlines = setheaderlines() add_paragraph_with_lines("DAILY procedure", 3, lines=hlines) # if not dry_run: remove_tmp() # if not dry_run: purge_account() # services() # check_daily_errors() # disk()