博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
超强的盘柜监控
阅读量:6070 次
发布时间:2019-06-20

本文共 3690 字,大约阅读时间需要 12 分钟。

[背景]公司最近HP盘柜出了几次问题,与其交涉也没得到很好的解决,为此让我们用脚本来监控日志,经观察日志,发现出现Source name为Ftdisk

出现盘柜丢失!为此,我就以这个关键字为基础,写了一个WMI脚本!

这个脚本有几个作用:

(1)拒绝重复发邮件(一个开关文件status.txt)

(2)发邮件报警(在备份日志功能上,我们通过循环做到不发给某个组)

(3)system日志检查(检索符合Ftdisk的条目并且发邮件)

(4)检查system日志大小,当大与1.2M时备份日志发邮件并且清除日志!(在小日志下检索,好处?不用说了吧!)

(5)动态获取本机IP

[过程]

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'用来监控日志信息将其匹配的信息发送邮件并指定超过一定大小的情况下备份日志                                         '

'版权所有:坏男孩                                                                                                 '

'MSN:[email]hahazhu0634@live.cn[/email]                                                                                        '

'QQ:383088680                                                                                                    '

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'定义些基本的全局变量

Dim arrFileLines()

i = 0

Dim emails(4)

emails(0)="[email]xxx@xxx.com[/email]"

emails(1)="[email]xxx@xxx.com[/email]"

emails(2)="[email]xxx@xxx.com[/email]"

emails(3)="[email]xxx@xxx.com[/email]"

IP=GetIP

'读取开关文件

Set objFSO = CreateObject(".ing.FileSystemObject")

Set objFile = objFSO.OpenTextFile("C:\status.txt", 1)

Do Until objFile.AtEndOfStream

     Redim Preserve arrFileLines(i)

     arrFileLines(i) = objFile.ReadLine

     i = i + 1

Loop

objFile.Close

For l = Ubound(arrFileLines) to LBound(arrFileLines) Step -1

    value=arrFileLines(l)

Next

if value = 1 then

  w..quit

else

   Checklog

end if

'检索日志函数

public Function Checklog

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colLoggedEvents = objWMIService.ExecQuery _

    ("Select * from Win32_NTLogEvent Where Logfile = 'System'" _

        & "and SourceName = 'Ftdisk'")

For Each objEvent in colLoggedEvents

  if objEvent.SourceName="Ftdisk" then

    call SendMail(IP&" Maybe disk error! ",3)

    Insert

    W..quit

  else

    checklogsize

  end if

Next

End Function

'发送邮件

Public Function SendMail(messages,count)

      for i=0 to count

           Set objEmail = CreateObject("CDO.Message")

            objEmail.From = "[email]zhengjun.zhu@163.com[/email]"

            objEmail.To = emails(i)

            objEmail.Subject = "DISK Status!"

            objEmail.Textbody ="Disk alarm:"&messages

            objEmail.Configuration.Fields.Item _

            ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

            objEmail.Configuration.Fields.Item _

            ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _

            "192.168.xxx.xxx" 

            objEmail.Configuration.Fields.Item _

            ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

            objEmail.Configuration.Fields.Update

            objEmail.Send

      next


End Function

'向开关文件写个1

Public Function Insert

        Set fs = CreateObject(".ing.FileSystemObject")

        Set txt = fs.OpenTextFile("c:/status.txt", 2, True) 

        txt.WriteLine "1"

        txt.close

End Function

'检查日志大小,备份/清除,退出

Public Function Checklogsize

   strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

   & "{impersonationLevel=impersonate, (Backup)}!\\" _

        & strComputer & "\root\cimv2")

Set colLogFiles = objWMIService.ExecQuery _

    ("Select * from Win32_NTEventLogFile Where LogFileName = 'System'")

For each objLogfile in colLogFiles

     if objLogFile.FileSize >1200000 then

         errBackupLog = objLogFile.BackupEventLog("c:\System.evt")

            If errBackupLog <> 0 Then        

                call SendMail(IP&" Log backup error!",2)

                w..quit

            else

                call SendMail(IP&" Log backup sucess!",2)

                objLogFile.ClearEventLog()

                w..quit

            end if

     else

          w..quit


     end if             

Next

End Function

'获取本机IP地址

Public Function GetIP

    ComputerName="."

    Dim objWMIService,colItems,objItem,objAddress

    Set objWMIService = GetObject("winmgmts:\\" & ComputerName & "\root\cimv2")

    Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")

    For Each objItem in colItems

        For Each strAddress in objItem.IPAddress

            GetIP=strAddress

        Next

    Next

End Function

[结果]等到下星期布属,如果兄弟们有什么高招,或者在性能上能更能提高脚本,请赐教!谢谢....

本文转自hahazhu0634 51CTO博客,原文链接:http://blog.51cto.com/5ydycm/126758,如需转载请自行联系原作者

你可能感兴趣的文章
mysql-mmm主主复制
查看>>
vim复制,粘贴,删除,撤销,替换,光标移动等用法
查看>>
数据库纯净下的主从复制
查看>>
salt state——salt的集中安装与配置(1)
查看>>
Ubuntu lnmp环境安装扩展插件mcrypt和crul
查看>>
华硕笔记本更换操作系统的一波三折的遭遇
查看>>
Jenkins 如何配置发邮箱
查看>>
VSAN API 探索第 7 部分 – VSAN 数据存储文件夹管理
查看>>
WebAPi的可视化输出模式(RabbitMQ、消息补偿相关)所有webapi似乎都缺失的一个功能...
查看>>
js练习本
查看>>
mysql的innodb中事务日志ib_logfile
查看>>
Java命令: jps
查看>>
鬼谷子
查看>>
我的友情链接
查看>>
Microsoft Visual SourceSafe OLE Automation
查看>>
android源码是不是包含联想的支持?
查看>>
iostat 命令监控磁盘IO
查看>>
java反射详解
查看>>
android无法识别adb devices解决方法
查看>>
站长常用服务器软件总结
查看>>