Ejemplo n.º 1
0
func Disk(os string, function string, object_config map[string]map[string]interface{}, object_tag config_parser.Server, messages chan string) {
	var disk string
	var data = make(map[string]string)
	var re = regexp.MustCompile(`[\n%a-zA-Z ]`)

	data["centos"] = "df -P | grep '/mapper/' | rev | cut -d ' ' -f1,2 | rev"
	data["fedora"] = "df -P | grep '/mapper/' | rev | cut -d ' ' -f1,2 | rev"
	data["alpine linux"] = "df -P | grep '/mapper/' | rev | cut -d ' ' -f1,2 | rev"

	disk_cmd := exec.Command("sh", "-c", data[os])
	disk_out, err := disk_cmd.Output()
	if err != nil {
		log.Fatal(err)
	}

	disk_data := strings.TrimSpace(string(disk_out[:]))
	list_disk := strings.Split(disk_data, "\n")
	for _, disk_element := range list_disk {
		disk_info := strings.Split(disk_element, " ")
		disk += "disk," + object_tag.Tag + "," + "type=" + disk_info[1] + " value=" + re.ReplaceAllString(disk_info[0], "") + "\n"
		data_report.Pushbullet_report(function, object_config, "disk "+disk_info[1], disk_info[0])
	}

	messages <- disk
}
Ejemplo n.º 2
0
func Memory(os string, function string, object_config map[string]map[string]interface{}, object_tag config_parser.Server, messages chan string) {
	var re = regexp.MustCompile(`[\n%a-zA-Z ]`)
	f, err := ioutil.ReadFile("/proc/meminfo")

	if err != nil {
		log.Fatal(err)
	}

	var str_memory_usage string
	lines := strings.Split(string(f), "\n")
	for _, line := range lines {
		fields := strings.SplitN(line, ":", 2)

		if fields[0] == "Active" {
			str_memory_usage = strings.TrimSpace(fields[1])
			str_memory_usage = strings.Replace(str_memory_usage, " kB", "", -1)
			int_memory_usage, _ := strconv.Atoi(str_memory_usage)
			int_memory_usage = int_memory_usage / 1024
			str_memory_usage = strconv.Itoa(int_memory_usage) + "MB"
		}
	}

	data_report.Pushbullet_report(function, object_config, "Memory", str_memory_usage)

	memory := "memory" + "," + object_tag.Tag + "," + "type=memory_usage" + " value=" + re.ReplaceAllString(str_memory_usage, "")

	messages <- memory
	//fmt.Println(memory)
	//return memory
}
Ejemplo n.º 3
0
func Httpd(os string, function string, object_config map[string]map[string]interface{}, object_tag config_parser.Server, messages chan string) {

	out, err := exec.Command("bash", "-c", "cat `whereis apache2`/logs/access_log | wc -l").Output()

	if err != nil {
		log.Fatal(err)
	}

	access_log := string(out[:])
	httpd := "httpd" + "," + object_tag.Tag + "," + "type=httpd" + " value=" + access_log
	data_report.Pushbullet_report(function, object_config, "httpd", access_log)

	messages <- httpd
}
Ejemplo n.º 4
0
func GetCPUUsage(os string, function string, object_config map[string]map[string]interface{}, object_tag config_parser.Server, messages chan string) {
	idle0, total0 := Get_CPU_Sample()
	time.Sleep(1 * time.Second)
	idle1, total1 := Get_CPU_Sample()

	idleTicks := float64(idle1 - idle0)
	totalTicks := float64(total1 - total0)
	cpuUsage := 100 * (totalTicks - idleTicks) / totalTicks

	// data_report.Pushbullet_report(function, object_config, "CPUUsage", strconv.FormatFloat(cpuUsage, 'f', -1, 64))
	data_report.Pushbullet_report(function, object_config, "CPUUsage", cpuUsage)

	cpuUsage_msg := "cpuusage" + "," + object_tag.Tag + "," + "type=cpu_usage" + " value=" + strconv.FormatFloat(cpuUsage, 'f', -1, 64) + "\n"

	messages <- cpuUsage_msg
}
Ejemplo n.º 5
0
func Uptime(os string, function string, object_config map[string]map[string]interface{}, object_tag config_parser.Server, messages chan string) {
	f, err := ioutil.ReadFile("/proc/uptime")

	if err != nil {
		log.Fatal(err)
	}

	content := strings.TrimSpace(string(f))
	fields := strings.Fields(content)
	uptime_total := fields[0]
	uptime_idle := fields[1]

	data_report.Pushbullet_report(function, object_config, "Uptime", uptime_total)

	uptime := "uptime" + "," + object_tag.Tag + "," + "type=uptime_total" + " value=" + uptime_total
	uptime += "uptime" + "," + object_tag.Tag + "," + "type=uptime_idle" + " value=" + uptime_idle

	messages <- uptime
	//fmt.Println(uptime)
	//return uptime
}
Ejemplo n.º 6
0
func Ccu(os string, function string, object_config map[string]map[string]interface{}, object_tag config_parser.Server, messages chan string) {
	var data = make(map[string][]byte)
	var return_value string
	// var notification string
	data["centos"] = []byte("/usr/sbin/ss -a | grep -v '*\\|127.0.0.1\\|Address' | sed -e '/^$/d'  | wc -l")
	data["ubuntu"] = []byte("/usr/sbin/ss -a | grep -v '*\\|127.0.0.1\\|Address' | sed -e '/^$/d'  | wc -l")
	data["fedora"] = []byte("/usr/sbin/ss -a | grep -v '*\\|127.0.0.1\\|Address' | sed -e '/^$/d'  | wc -l")

	cmd := string(data[os][:])
	out, err := exec.Command("bash", "-c", cmd).Output()
	result := string(out[:])
	if err == nil {
		fmt.Println(result)
		return_value = "ccu" + "," + object_tag.Tag + " value=" + result
	} else {
		log.Fatal(err)
	}

	data_report.Pushbullet_report(function, object_config, "CCU", result)

	messages <- return_value
}
Ejemplo n.º 7
0
func LoadAvg(os string, function string, object_config map[string]map[string]interface{}, object_tag config_parser.Server, messages chan string) {
	f, err := ioutil.ReadFile("/proc/loadavg")

	if err != nil {
		log.Fatal(err)
	}

	content := strings.TrimSpace(string(f))
	fields := strings.Fields(content)

	loadavg1min := fields[0]
	loadavg5min := fields[1]
	loadavg15min := fields[2]

	// warning_threshold := object_config["loadavg"]["warning"].(int)
	// critical_threshold := object_config["loadavg"]["critical"].(int)
	data_report.Pushbullet_report(function, object_config, "LoadAvg1Min", loadavg1min)

	loadavg := "loadavg" + "," + object_tag.Tag + "," + "type=loadavg1min" + " value=" + loadavg1min + "\n"
	loadavg += "loadavg" + "," + object_tag.Tag + "," + "type=loadavg5min" + " value=" + loadavg5min + "\n"
	loadavg += "loadavg" + "," + object_tag.Tag + "," + "type=loadavg15min" + " value=" + loadavg15min + "\n"

	messages <- loadavg
}