Beispiel #1
0
//PrintForInfluxDB prints the data in influxdb lineformat
func (p PerformanceData) PrintForInfluxDB(version string) string {
	if helper.VersionOrdinal(version) >= helper.VersionOrdinal("0.9") {
		tableName := fmt.Sprintf(`metrics,host=%s`, helper.SanitizeInfluxInput(p.hostname))
		if p.service == "" {
			tableName += fmt.Sprintf(`,service=%s`, helper.SanitizeInfluxInput(config.GetConfig().Influx.HostcheckAlias))
		} else {
			tableName += fmt.Sprintf(`,service=%s`, helper.SanitizeInfluxInput(p.service))
		}
		tableName += fmt.Sprintf(`,command=%s,performanceLabel=%s`,
			helper.SanitizeInfluxInput(p.command),
			helper.SanitizeInfluxInput(p.performanceLabel),
		)
		if len(p.tags) > 0 {
			tableName += fmt.Sprintf(`,%s`, helper.PrintMapAsString(helper.SanitizeMap(p.tags), ",", "="))
		}
		if p.unit != "" {
			tableName += fmt.Sprintf(`,unit=%s`, p.unit)
		}

		tableName += fmt.Sprintf(` %s`, helper.PrintMapAsString(helper.SanitizeMap(p.fields), ",", "="))
		tableName += fmt.Sprintf(" %s\n", p.time)
		return tableName
	}
	return ""
}
//searchAltCommand looks for alternative command name in perfdata
func (w *NagiosSpoolfileWorker) searchAltCommand(perfData, command string) string {
	result := command
	search := w.regexAltCommand.FindAllStringSubmatch(perfData, 1)
	if len(search) == 1 && len(search[0]) == 2 {
		result = search[0][1]
	}
	return helper.SanitizeInfluxInput(splitCommandInput(result))
}
func (notification *NotificationData) sanitizeValues() {
	notification.Data.sanitizeValues()
	notification.notificationType = helper.SanitizeInfluxInput(notification.notificationType)
	notification.notificationLevel = helper.SanitizeInfluxInput(notification.notificationLevel)
}
//Iterator to loop over generated perf data.
func (w *NagiosSpoolfileWorker) old_performanceDataIterator(input map[string]string) <-chan PerformanceData {
	ch := make(chan PerformanceData)
	var typ string
	if isHostPerformanceData(input) {
		typ = hostType
	} else if isServicePerformanceData(input) {
		typ = serviceType
	} else {
		if len(input) > 1 {
			logging.GetLogger().Info("Line does not match the scheme", input)
		}
		close(ch)
		return ch
	}
	//logging.GetLogger().Info("XX INPUT XX", input)
	currentHostname := helper.SanitizeInfluxInput(input[hostname])
	currentCommand := w.searchAltCommand(input[typ+"PERFDATA"], input[typ+checkcommand])
	currentTime := helper.CastStringTimeFromSToMs(input[timet])
	currentService := ""
	if typ != hostType {
		currentService = helper.SanitizeInfluxInput(input[servicedesc])
	}
	//        logging.GetLogger().Info("XX currentHostname XX ", currentHostname)
	//        logging.GetLogger().Info("XX currentCommand XX  ", currentCommand)
	//        logging.GetLogger().Info("XX currentTime XX     ", currentTime)
	//        logging.GetLogger().Info("XX currentService XX  ", currentService)
	//currentCommand = strings.Replace(currentCommand, "check_mk-", "", -1)

	go func() {
		for _, value := range w.regexPerformancelable.FindAllStringSubmatch(input[typ+"PERFDATA"], -1) {
			perf := PerformanceData{
				hostname:         currentHostname,
				service:          currentService,
				command:          currentCommand,
				time:             currentTime,
				performanceLabel: helper.SanitizeInfluxInput(value[1]),
				unit:             helper.SanitizeInfluxInput(value[3]),
				fieldseperator:   w.fieldseperator,
				tags:             map[string]string{},
			}

			for i, data := range value {
				if i > 1 && i != 3 && data != "" {
					performanceType, err := indexToperformanceType(i)
					if err != nil {
						logging.GetLogger().Warn(err, value)
						continue
					}

					//Add downtime tag if needed
					if performanceType == "value" && w.livestatusCacheBuilder.IsServiceInDowntime(perf.hostname, perf.service, input[timet]) {
						perf.tags["downtime"] = "1"
					}

					//logging.GetLogger().Info("XX hostname:         ",perf.hostname)
					//logging.GetLogger().Info("XX service:          ",perf.service)
					//logging.GetLogger().Info("XX command:          ",perf.command)
					//logging.GetLogger().Info("XX time:             ",perf.time)
					//logging.GetLogger().Info("XX performanceLabel: ",perf.performanceLabel)
					//logging.GetLogger().Info("XX performanceType:  ",perf.performanceType)
					//logging.GetLogger().Info("XX unit:             ",perf.unit)
					////logging.GetLogger().Info("XX tags:             ",perf.tags)
					//for key, value := range perf.tags {
					//logging.GetLogger().Info("XX tag - ",key , "        ",value)
					////fmt.Println("Key:", key, "Value:", value)
					//}
					if performanceType == "warn" || performanceType == "crit" {
						//Range handling
						rangeRegex := regexp.MustCompile(`[\d\.\-]+`)
						rangeHits := rangeRegex.FindAllStringSubmatch(data, -1)
						if len(rangeHits) == 1 {
							perf.tags["fill"] = "none"
							perf.tags["type"] = performanceType
							perf.value = helper.StringIntToStringFloat(rangeHits[0][0])
							perf.performanceType = performanceType
							ch <- perf
						} else if len(rangeHits) == 2 {
							//If there is a range with no infinity as border, create two points
							perf.performanceType = performanceType
							if strings.Contains(data, "@") {
								perf.tags["fill"] = "inner"
							} else {
								perf.tags["fill"] = "outer"
							}

							for i, tag := range []string{"min", "max"} {
								tmpPerf := perf
								tmpPerf.tags = helper.CopyMap(perf.tags)
								tmpPerf.tags["type"] = tag
								tmpPerf.value = helper.StringIntToStringFloat(rangeHits[i][0])
								ch <- tmpPerf
							}
						} else {
							logging.GetLogger().Warn("Regexmatching went wrong", rangeHits)
						}

					} else {
						perf.tags["fill"] = "none"
						perf.tags["type"] = "value"
						perf.value = helper.StringIntToStringFloat(data)
						perf.performanceType = performanceType
						ch <- perf
					}
				}
			}
		}
		close(ch)
	}()
	return ch
}
Beispiel #5
0
//Escape all bad chars.
func (live *Data) sanitizeValues() {
	live.hostName = helper.SanitizeInfluxInput(live.hostName)
	live.serviceDisplayName = helper.SanitizeInfluxInput(live.serviceDisplayName)
	live.entryTime = helper.SanitizeInfluxInput(live.entryTime)
	live.author = helper.SanitizeInfluxInput(live.author)
}
Beispiel #6
0
func (comment *LivestatusCommentData) sanitizeValues() {
	comment.LivestatusData.sanitizeValues()
	comment.entry_type = helper.SanitizeInfluxInput(comment.entry_type)
}
Beispiel #7
0
func (notification *LivestatusNotificationData) sanitizeValues() {
	notification.LivestatusData.sanitizeValues()
	notification.notification_type = helper.SanitizeInfluxInput(notification.notification_type)
	notification.notification_level = helper.SanitizeInfluxInput(notification.notification_level)
}
Beispiel #8
0
//Escape all bad chars.
func (live *LivestatusData) sanitizeValues() {
	live.host_name = helper.SanitizeInfluxInput(live.host_name)
	live.service_display_name = helper.SanitizeInfluxInput(live.service_display_name)
	live.entry_time = helper.SanitizeInfluxInput(live.entry_time)
	live.author = helper.SanitizeInfluxInput(live.author)
}
Beispiel #9
0
func (downtime *LivestatusDowntimeData) sanitizeValues() {
	downtime.LivestatusData.sanitizeValues()
	downtime.end_time = helper.SanitizeInfluxInput(downtime.end_time)
}
Beispiel #10
0
func (downtime *DowntimeData) sanitizeValues() {
	downtime.Data.sanitizeValues()
	downtime.endTime = helper.SanitizeInfluxInput(downtime.endTime)
}