Merge pull request #2 from LucaAust/improve-css-for-html-output

improve css for html output
This commit is contained in:
Thorsten Spille 2021-12-14 14:56:25 +01:00 committed by GitHub
commit 14501aa212
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -61,6 +61,7 @@ import json
import os.path import os.path
import os import os
import socket import socket
from datetime import datetime
from email.message import EmailMessage from email.message import EmailMessage
from email.mime.application import MIMEApplication from email.mime.application import MIMEApplication
from email.utils import formatdate from email.utils import formatdate
@ -660,17 +661,31 @@ class zfscheck(object):
_header_names = [self.COLUMN_NAMES.get(i,i) for i in _header] _header_names = [self.COLUMN_NAMES.get(i,i) for i in _header]
_converter = dict((i,self.COLUMN_MAPPER.get(i,(lambda x: str(x)))) for i in _header) _converter = dict((i,self.COLUMN_MAPPER.get(i,(lambda x: str(x)))) for i in _header)
_hostname = socket.getfqdn() _hostname = socket.getfqdn()
_out = []
_out.append("<html><head>") _out = "<html>"
_out.append("<meta name='color-scheme' content='only'>") _out += "<head>"
_out.append("<style type='text/css'>td {font-weight: bold;} .warn { background-color: yellow; color: black; } .crit { background-color: red; color: black;}</style>") _out += "<meta name='color-scheme' content='only'>"
_out.append("<title>ZFS</title></head>") _out += "<style type='text/css'>"
_out.append(f"<body><h2>{_hostname}</h2>") _out += "html{height:100%%;width:100%%;}"
_out.append("<table border=1>") _out += "body{color:black;width:auto;padding-top:2rem;}"
_out.append("<tr><th>{0}</th></tr>".format("</th><th>".join(_header_names))) _out += "h1,h2{text-align:center;}"
_out += "table{margin: 2rem auto;}"
_out += "table,th,td {border:1px solid black;border-spacing:0;border-collapse:collapse;padding:.2rem;}"
_out += "th{text-transform:capitalize}"
_out += "td:first-child{text-align:center;font-weight:bold;text-transform:uppercase;}"
_out += "td:last-child{text-align:right;}"
_out += ".warn{background-color:yellow;}"
_out += ".crit{background-color:red;color:black;}"
_out += "</style>"
_out += "<title>Check ZFS</title></head><body>"
_out += f"<h1>{_hostname}</h1><h2>{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}</h2>"
_out += "<table>"
_out += "<tr><th>{0}</th></tr>".format("</th><th>".join(_header_names))
for _item in self._datasort(data): for _item in self._datasort(data):
_out.append("<tr class='{1}'><td>{0}</td></tr>".format("</td><td>".join([_converter.get(_col)(_item.get(_col,"")) for _col in _header]),_converter["status"](_item.get("status","0")))) _out += "<tr class='{1}'><td>{0}</td></tr>".format("</td><td>".join([_converter.get(_col)(_item.get(_col,"")) for _col in _header]),_converter["status"](_item.get("status","0")))
_out.append("</table></body></html>")
_out += "</table></body></html>"
return "".join(_out) return "".join(_out)
def mail_output(self,data): def mail_output(self,data):