コード例 #1
0
ファイル: service.go プロジェクト: teh/elastic-journald
func (s *Service) ProcessEntryFields(row map[string]interface{}) {
	var length C.size_t
	var cData *C.char

	for C.sd_journal_restart_data(s.Journal); C.sd_journal_enumerate_data(s.Journal, (*unsafe.Pointer)(unsafe.Pointer(&cData)), &length) > 0; {
		data := C.GoString(cData)

		parts := strings.SplitN(data, "=", 2)

		key := strings.ToLower(parts[0])
		value := parts[1]

		switch key {
		// don't index bloat
		case "_cap_effective":
		case "_cmdline":
		case "_exe":
		case "_hostname":
		case "_systemd_cgroup":
		case "_systemd_slice":
		case "_transport":
		case "syslog_facility":
		case "syslog_identifier":
			continue
		default:
			row[strings.TrimPrefix(key, "_")] = value
		}
	}
}
コード例 #2
0
ファイル: service.go プロジェクト: iavael/elastic-journald
func (s *Service) ProcessEntryFields(row map[string]interface{}) {
	var length C.size_t
	var cData *C.char

	for C.sd_journal_restart_data(s.Journal); C.sd_journal_enumerate_data(s.Journal, (*unsafe.Pointer)(unsafe.Pointer(&cData)), &length) > 0; {
		data := C.GoString(cData)

		parts := strings.SplitN(data, "=", 2)

		key := strings.ToLower(parts[0])
		value := parts[1]

		row[strings.TrimPrefix(key, "_")] = value
	}
}
コード例 #3
0
ファイル: journal.go プロジェクト: mheese/go-systemd
func (j *Journal) GetDataAll() (JournalEntry, error) {
	data := make(JournalEntry)

	var d unsafe.Pointer
	var l C.size_t
	var cboot_id C.sd_id128_t
	var csid = C.CString("123456789012345678901234567890123")
	defer C.free(unsafe.Pointer(csid))
	var crealtime C.uint64_t
	var cmonotonic C.uint64_t
	var ccursor *C.char
	j.mu.Lock()
	// not in their own fields
	C.sd_journal_set_data_threshold(j.cjournal, 0)
	C.sd_journal_get_realtime_usec(j.cjournal, &crealtime)
	C.sd_journal_get_monotonic_usec(j.cjournal, &cmonotonic, &cboot_id)
	C.sd_id128_to_string(cboot_id, csid)
	C.sd_journal_get_cursor(j.cjournal, (**C.char)(&ccursor))
	defer C.free(unsafe.Pointer(ccursor))

	// reset to start the loop
	C.sd_journal_restart_data(j.cjournal)
	j.mu.Unlock()

	realtime := uint64(crealtime)
	monotonic := uint64(cmonotonic)
	cursor := C.GoString(ccursor)
	bootid := C.GoString(csid)

	data["__CURSOR"] = cursor
	data["__REALTIME_TIMESTAMP"] = realtime
	data["__MONOTONIC_TIMESTAMP"] = monotonic
	data["__BOOT_ID"] = bootid

	for {
		// retrieve new field
		j.mu.Lock()
		r := C.sd_journal_enumerate_data(j.cjournal, &d, &l)
		j.mu.Unlock()

		if r <= 0 {

			break
		}

		fieldData := C.GoBytes(d, C.int(l))
		name, value := splitNameValue(fieldData)
		addToMap(data, name, value)
	}

	// Add catalog data as well if there is a MESSAGE_ID
	_, ok := data["MESSAGE_ID"]
	if ok {
		catalogEntry, err := j.GetCatalog()
		if err == nil {
			data["CATALOG_ENTRY"] = catalogEntry
		}
	}

	return data, nil
}