• 大小: 12KB
    文件类型: .py
    金币: 1
    下载: 1 次
    发布日期: 2022-10-06
  • 语言: Python
  • 标签: snmp  

资源简介

GUI实现Net-SNMP监控主机CPU等信息代码,网络安全管理课程代码。开发 GUI 界面程序,使用户可通过控制台程序观察主机 CPU、内存、硬盘空间、流量值;开发阈值告警功能,用户通过界面可设置性能阈值(如 CPU),当超过阈值时自动报警。在控制台动态显示主机 CPU、内存利用曲线。

资源截图

代码片段和文件信息

#!/usr/bin/env python
#-*- coding:utf-8 -*-

import os sys
from tkinter import *
from tkinter.font import Font
from tkinter.ttk import *
from tkinter.messagebox import *
import tkinter.messagebox
import numpy as np  
import matplotlib.pyplot as plt  
import time  
import matplotlib  
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg  
from matplotlib.figure import Figure  
    #import tkinter.filedialog as tkFileDialog
    #import tkinter.simpledialog as tkSimpleDialog    #askstring()

class Application_ui(frame):
    #这个类仅实现界面生成功能,具体事件处理代码在子类Application中。
    def __init__(selfhost master=None):
        
        frame.__init__(self master)
        self.master.title(‘Form1‘)
        self.master.geometry(‘800x800‘)
        self.createWidgets(host)
        self.boolcurve=True

    def createWidgets(selfhost):
        self.CPU_threshhold=100.0
        self.top = self.winfo_toplevel()

        self.style = style()

        self.drawPicf = Figure(figsize=(13.54) dpi=50)  
        self.drawPiccanvas = FigureCanvasTkAgg(self.drawPicf master=self.top)   
        self.drawPiccanvas.draw()   
        self.drawPiccanvas.get_tk_widget().pack(anchor =‘se‘side=BOTTOM)

        self.drawPicfC = Figure(figsize=(13.54) dpi=50)  
        self.drawPiccanvasC = FigureCanvasTkAgg(self.drawPicfC master=self.top)   
        self.drawPiccanvasC.draw()   
        self.drawPiccanvasC.get_tk_widget().pack(anchor =‘se‘side=BOTTOM)

        self.Text1Var = StringVar(value=‘例如:1.3.6.1.2.1.1.1.0‘)
        self.Text1 = Entry(self.top text=‘Text1‘ textvariable=self.Text1Var font=(‘宋体‘9))
        self.Text1.place(relx=0.117 rely=0.029 relwidth=0.226 relheight=0.074)

        self.TextCPUVar = StringVar(value=‘CPU阈值(%)‘)
        self.TextCPU = Entry(self.top text=‘TextCPU‘ textvariable=self.TextCPUVar font=(‘宋体‘9))
        self.TextCPU.place(relx=0.117 rely=0.429 width=180 height=30)

        self.style.configure(‘Command1.TButton‘font=(‘宋体‘9))
        self.Command1 = Button(self.top text=‘结果‘ command=lambda:self.Command1_Cmd(host) style=‘Command1.TButton‘)        
        self.Command1.place(relx=0.01 rely=0.08 width=80 height=30)

        self.style.configure(‘Command3.TButton‘font=(‘宋体‘9))
        self.Command3 = Button(self.top text=‘CPU阈值设定‘ command=self.info_warn_err style=‘Command3.TButton‘)     
        self.Command3.place(relx=0.01 rely=0.429 width=80 height=30)

        self.style.configure(‘Command4.TButton‘font=(‘宋体‘9))
        self.Command4 = Button(self.top text=‘曲线开始/停止‘ command=lambda:self.stopcurve() style=‘Command4.TButton‘)     
        self.Command4.place(relx=0.01 rely=0.63 width=90 height=30)

        # self.style.configure(‘Command4.TButton‘font=(‘宋体‘9))
        # self.Command7 = Button(self.top text=‘曲线‘ command=lambda:self.refresh() style=‘Command7.TButton‘)     
        # self.Command7.place(relx=0.01 rely=0.73 width=80

评论

共有 条评论