Ejemplo n.º 1
0
        disk_space = get_disk_space(pub, hosts, index, db_connect)

        host_apps = get_host_apps(pub, hosts, db_connect)

        document = Document(os.path.join(doc_path, 'host-report-tpl.docx'))

        document.add_heading(add_head)

        chapter = Chapter(os.path.join(doc_path, 'host-summary-tpl.docx'))
        chapter.add_context({
            'date_cycle': date_cycle,
            'table': hosts,
            'fee': cost
        })
        document.add_chapter(chapter, title="主机明细总览", level=2)

        html_table(hosts, add_head, cost, date_cycle, download_url)

        for host in hosts:

            image_host_resource(doc_path, hosts_metrics, host)

            image_host_apps(doc_path, host_apps, host)

            ip = host['ip']
            id = host['id']

            document.add_heading("主机%s[%s]" % (ip, host['project']), level=2)

            chapter = Chapter(os.path.join(doc_path, 'host-property-tpl.docx'))
Ejemplo n.º 2
0
                result_doc.update({
                    'context':
                    result_doc.get('ExceptionType') + "," +
                    str(result_doc.get('count'))
                })
                result_doc.update({'sumCount': 1})
                host_mongo_query_exceptions.update({new_id: result_doc})
    # host_mongo_query_exceptions = sorted(host_mongo_query_exceptions.items(), key=lambda d: d[0])

    logging.info(
        f'host_mongo_query_exceptions is {host_mongo_query_exceptions}')
    # \\print(sorted(host_mongo_query_exceptions.items(), key=lambda d: d[0]))
    doc_path = '/Users/mtr/PycharmProjects/mongoQuery/com/asiainfo/aihc/doc_1_20190807'
    document = Document(os.path.join(doc_path, 'host-report-tpl.docx'))
    chapter = Chapter(
        os.path.join(doc_path, 'host-mongo_query_exceptions-tpl.docx'))

    # host_mongo_query_exceptions = [{'ip': '10.19.85.33', 'FunctionName': 'load', 'count': '10',
    #                                 'context': 'NullPointException:1,RuntimeException:3'},
    #                                {'ip': '10.19.85.34', 'FunctionName': 'serv', 'count': '20',
    #                                 'context': 'NullPointException:2,RuntimeException:6'}]
    excep_result = host_mongo_query_exceptions.values()
    logging.info(f'excep_result is {excep_result}')
    table = {'table': excep_result}
    chapter.add_context(table)
    print(f"host-mongo_query_exceptions table  is {table}")
    document.add_chapter(chapter, title="异常数量统计", level=2)
    document.render()
    document.save(
        os.path.join(doc_path, '%s云主机使用情况.docx' % ('mongo_query_exception')))