首页 > 编程语言 >安全巡检 python HTML报告

安全巡检 python HTML报告

时间:2022-09-18 00:55:22浏览次数:67  
标签:巡检 python results HTML xunjian result margin permitroot

1.报表模板

[root@yinliao-yanshi report_jinja2]# cat xunjian_table.html 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>insight report</title>
</head>
<style type="text/css">
    h1 {margin-left: 20px}
    h2 {margin-left: 20px;
        font-size: 19px;
        font-weight: bold;
        display: inline-block;
        padding-left: 10px;
        border-left: 5px solid #916dd5;}
    h3 {margin-left: 20px}
    h4 {margin-left: 20px;
        margin-bottom: -5px}
    table {margin-left: 20px;
           margin-top: 5px;
           margin-bottom: 5px}
    p {margin-left: 20px}
    a {margin-top: 200px;}
    </style>
<h1>巡检报告</h1>
<body>
<h2>一、巡检详情</h2>
<p>巡检描述:{{ xunjian_description }}</p>
<p>巡检时间段:{{ start_time }} --> {{ end_time }} </p>
<p>巡检人:{{ people }}</p>
</body>
</html>



<h2>二、巡检结果</h2>

    <table border="1" width = "40%" cellspacing='0' cellpadding='0'>
    <tr>
        <th>ID</th>
        <th>指标描述</th>
        <th>巡检结果</th>
        <th>是否通过</th>
    </tr>

    {% for item in items %}
    <tr align='center'>
        <td>{{ item.ID }}</td>
        <td>{{ item.指标描述 }}</td>
        <td>{{ item.巡检结果 }}</td>
        <td>{{ item.是否通过 }}</td>
    </tr>
    {% endfor%}
    </table>
[root@yinliao-yanshi report_jinja2]#

2. python脚本

[root@yinliao-yanshi report_jinja2]# cat xunjian_command_result.py 
#!/usr/bin/python3
# -*-  coding=utf-8 -*-
# author: xiaoweige
import subprocess
from jinja2 import Environment, FileSystemLoader

overall_info={'xunjian_description': '第一个巡检报告',
'start_time': '2020-01-01',
'end_time': '2021-06-01',
'people': "小伟哥"}

all_dict_list = []

complex_results = {"ID":1,"指标描述":"密码复杂度"}
shell_result = subprocess.check_output("egrep '^password.*minlen.*ocredit'  /etc/pam.d/system-auth |wc -l", shell=True).decode().strip().split('\n')
print("密码复杂度 command result: {}".format(shell_result[0]))
if shell_result[0] =="1":
    complex_results["巡检结果"]=1    
    complex_results["是否通过"]="是"

else:
    complex_results["巡检结果"]=0
    complex_results["是否通过"]="否"
all_dict_list.append(complex_results)


permitroot_results = {"ID":2,"指标描述":"禁用root用户登录"}
permitroot_result = subprocess.check_output("egrep '^PermitRootLogin.*no'   /etc/ssh/sshd_config |wc -l", shell=True).decode().strip().split('\n')
print("禁用root用户登录 command result: {}".format(permitroot_result[0]))
if permitroot_result[0] =="1":
        permitroot_results["巡检结果"]=1
        permitroot_results["是否通过"]="是"

else:
        permitroot_results["巡检结果"]=0
        permitroot_results["是否通过"]="否"

all_dict_list.append(permitroot_results)


print('permitroot_results: {} \n'.format(all_dict_list))


env = Environment(loader=FileSystemLoader('./'))
template = env.get_template('xunjian_table.html')
with open("xunjian_out.html", 'w+', encoding='utf-8') as f:
    out = template.render(xunjian_description=overall_info['xunjian_description'],
                          start_time=overall_info['start_time'],
                          end_time=overall_info['end_time'],
                          people=overall_info['people'],
                          items = all_dict_list)
    f.write(out)
    f.close()


[root@yinliao-yanshi report_jinja2]# 

 

 

标签:巡检,python,results,HTML,xunjian,result,margin,permitroot
From: https://www.cnblogs.com/hixiaowei/p/16704045.html

相关文章

  • python调用第三方接口
    为什么要用python调用第三方接口?以往总是会想当然的认为,调用第三方接口只能是前端的工作,但最近在做一个程序时发现,这项工作完全可以使用python来解决,挺惊喜的,毕竟这样就可......
  • python re包 正则表达式
    Python正则表达式正则表达式是一个特殊的字符序列,它能帮助你方便的检查一个字符串是否与某种模式匹配。在python中提供了一个使用正则的模块re。re模块使Python语言......
  • 【Python小工具】文件解压
    文件解压#-*-coding:utf-8-*-importosimportsysimporttimeimportshutilimportfiletypeimportgzipimporttarfileimportzipfileclassFileUtils:......
  • python中的defaultdict类型
    Python内置的字典类型挺好用,但有一个很麻烦的缺点,当查询的键不存在时,就会报KeyError的错误,影响程序的正常使用,虽然可以用异常捕获处理,但有时候还是不太方便. ......
  • VSCode安装和Python安装及其配置【转载】
    VisualStudioCode(VSCode)是微软出品的一款可扩展的轻量级开源编辑器,并且支持全平台系统。这些特性使得VSCode颇受欢迎,可以说是目前最火的代码编辑器之一了,在程序员圈子里,......
  • 纯html+css 实现滚动新闻
    CSS3实现滚动字幕效果(即跑马灯)参考 https://www.cnblogs.com/h5n1/archive/2012/03/03/2378397.html -本周亮点-本周图书国庆特大书讯我们虚位以待你准......
  • python :生成条形码
    1importbarcode2frombarcode.writerimportImageWriter34#Definecontentofthebarcodeasastring5number=input("Enterthecodetogenerateba......
  • HTML
    基本概念内联元素(inline)特点:动态分配分类:链接元素;文本元素;图片元素;范围元素注意:内联元素不可嵌套块级元素块级元素(block)特点:独占一行分类:标题元素......
  • Python话题抓取
    话题抓取通过话题入口抓取话题下所有问题和回答数据存储MySQL:topicquestionanswer数据抓取requwsts/xpath/re配置maccookie解密chromecookie文件变更https......
  • Python中的类与对象
    类的创建classStudent native_place='吉林' def__init__(self,name,age): self.name=name#把局部变量name的值赋给实体属性self.name self.age=age#实例方法......