Script for regular Server check

Source: Internet
Author: User
Tags stringreplace

I wrote a script and run it before going to work every day. I emailed myself the check result report and forwarded it to the Internet mailbox of the text message notification, you can check whether there are any faults or servers before you go to work.


The inspection content is constantly improved. Now you can know whether all the IP devices on the attendance machine, printer, monitoring, UPS, routers, and switches are connected. Whether the file sharing server and website can be accessed normally. Windows server startup time, memory usage, hard disk available space, and so on.

Check the email to check the status of all devices and servers. You do not need to check the email one by one.

Check whether a universal Ping is connected to the returned results. fileexists is used for file access. The website class checks the inetread returned results. The Windows server class uses WMI for query.


Query part of the Windows server code in the domain:

; Query Windows Server local $ queryserverip = stringsplit ($ winserveriplist, ",") for $ I = 1 to ubound ($ queryserverip) -1 Local $ queryserver = Ping ($ queryserverip [$ I], 1000) If $ queryserver then; if a value greater than 0 was returned then display the following message. dim $ bodytable, $ partspaceinfo $ obw.miservice = objget ("winmgmts: \" & $ queryserverip [$ I] & "\ Root \ cimv2") $ colitems = $ obw.miservice. execquery ("select * From win32_operatingsystem") for $ colitem in $ colitems $ osversion = $ colitem. version if $ colitem. freephysicalmemory <$ alarmfreephysicalmemory then $ freephysicalmemory = '<font size = "3" color = "# fe642e">' & round ($ colitem. freephysicalmemory/1048576, 2) & "G </font>" else $ freephysicalmemory = round ($ colitem. freephysicalmemory/1048576, 2) & "G" endif $ totalvisiblememorysize = round ($ colitem. totalvisiblememorysize/1048576, 2) & "G" $ lastboottime = stringtrimright ($ colitem. lastbootuptime, 11) $ lastboottime = stringregexpreplace ($ lastboottime, '(\ D {4}) (\ D) (\ D) ',' $1-$2-$3 $4: $5: $6 ') if _ datediff ('D', $ lastboottime, _ nowcalc () <1 then; less than 1, that is, the start time is less than one day. $ lastboottime = '<font size = "3" color = "# fe642e">' & $ lastboottime & '</font> 'endif next if $ osversion <5.1 then; windows 2000 $ colitems = $ ob1_miservice. execquery ("select * From win32_perfrawdata_perfos_system") for $ colitem in $ colitems $ intperftimestamp = $ colitem. timestamp_object $ intperftimefreq = $ colitem. frequency_object $ intcounter = $ colitem. systemuptime $ osversion = $ colitem. versionnext; Calculate the Win2000 start time $ iuptimeinsec = ($ intperftimestamp-$ intcounter)/$ timeout $ bootupdays = $ iuptimeinsec/60/60/24 $ seconds = changetoseconds ($ bootupdays) $ lastboottime = _ dateadd ('s ',-$ seconds, _ nowcalc () If _ datediff ('D', $ lastboottime, _ nowcalc () <1 then; less than 1, that is, the start time is less than one day. $ lastboottime = '<font size = "3" color = "# fe642e">' & $ lastboottime & '</font> 'endif endif $ colitems = $ ob1_miservice. execquery ("select * From win32_logicaldisktopartition") Local $ partspaceinfo = ""; clear $ partspaceinfo; otherwise, accumulate for $ objitem in $ colitems $ diskfh = stringleft (stringright ($ objitem. dependent, 3), 2) $ coldiskitems = $ ob1_miservice. execquery ("select * From win32_logicaldisk where DeviceID = '" & $ diskfh & "'") for $ coldiskitem in $ coldiskitems; $ diskfhspaceinfo = stringreplace ($ diskfh ,":", "disk available") & calckmg ($ coldiskitem. freespace) & "/total" & calckmg ($ coldiskitem. size) & @ Cr $ diskfhfreespace = calckmg ($ coldiskitem. freespace) If $ coldiskitem. freespace <$ alarmfreespace then $ diskfhfreespace = '<font size = "3" color = "# fe642e">' & calckmg ($ coldiskitem. freespace) & '</font> 'else $ diskfhfreespace = calckmg ($ coldiskitem. freespace) endif $ diskfhspaceinfo = $ diskfh & $ diskfhfreespace & "/" & calckmg ($ coldiskitem. size) & @ Cr next $ partspaceinfo = $ partspaceinfo & $ diskfhspaceinfo next $ bodytable = $ bodytable & '<tr> <TD>' & servername ($ queryserverip [$ I]) & '</TD> <TD>' & $ queryserverip [$ I] & '</TD> <TD>' & $ queryserver & 'millisecond </TD> <TD> '& $ lastboottime &' </TD> <TD> '& $ freephysicalmemory & "/" & $ totalvisiblememorysize &' </TD> <TD> '& $ partspaceinfo &' </TD> /TD> </tr> 'else $ bodytable = $ bodytable & '<tr> <TD>' & servername ($ queryserverip [$ I]) & '</TD> <TD>' & $ queryserverip [$ I] & '</TD> <font size = "3" color = "red"> disconnected </font> </TD> <TD> '& $ lastboottime &' </TD> <TD> '& $ freephysicalmemory & "/" & $ totalvisiblememorysize &' </TD> <TD> '& $ partspaceinfo &' </TD> </tr> '$ subject = 'faulty-' & stringreplace ($ subject, 'fault-', "") endifnext $ body = $ Body & $ bodytable & "</table> <br>"


This article is from the "temporary blog" blog, please be sure to keep this source http://gzzhang.blog.51cto.com/5312382/1546939

Script for regular Server check

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.