This is a creation in Article, where the information may have evolved or changed.
Because the server is more, used to like to write programs in Perl, and later found that the deployment of the Perl environment is also installed, it is too troublesome, so instead of go programming, go to compile the post, copy to the server can run, and really busty convenient.
have already used go to write a MySQL master-slave synchronization, check whether the error from the server program, if the synchronization error can be in the Zabbix warning, the MySQL password written to the program, and then compiled, so much more secure than the scripting language, and do not add a user.
The reason is that, there are a lot of servers, a large part of the ordinary hard disk, the ordinary hard disk is prone to problems, because there is no way on the server to do badblock check (too much consumption of IO resources), but check the S.M.A.R.T state can anticipate the hard disk failure, or a bit of use, better than no, right.
The program is based on Linux, window changes can also be used, mainly to check the/DEV/SDA...B...C...D loop check the system has how many hard disks, and then check the status, if the program returned 1 normal, the program returned 0 indicates that there is a problem with the hard disk.
package mainimport ("bytes" "Flag" "FMT" "Log" "OS" "Os/exec" "strings") Func pathexists (path String) (bool, error) {_, Err: = OS. Stat (path) if Err = = Nil {return true, Nil}if OS. Isnotexist (Err) {return false, Nil}return false, Err}func smartctl (dev string, debug int) int {path, err: = Exec. Lookpath ("Smartctl") if err! = Nil {log. Fatal (err)}cmd: = Exec.command (Path, "-H", Dev) var out bytes. Buffercmd.stdout = &outerr = cmd. Run () if err! = Nil {log. Fatal (Err)}//fmt. Printf ("%s\n", out. String ()) if strings. Contains (out). String (), "OK") | | Strings. Contains (out). String (), "PASSED") {if debug = = 1 {fmt. Printf ("%s test ok\n", Dev)}return 1}return 0}func Main () {debug: = flag. Int ("Debug", 0, "to debug-debug 1") flag. Parse () for _, Drive: = Range "ABCD" {//dev:=fmt. Sprintf ("/dev/sd%s", drive) Dev: = "/dev/sd" + string (drive)//fmt. Println (Dev) If ok, _: = Pathexists (dev); OK {mystat: = Smartctl (Dev, *debug) if Mystat ==0 {fmt. Print (0) OS. Exit ( -1)}}}fmt. Print (1)}