Esempio n. 1
0
func handleEvent(record map[string]interface{}, options MessagePrinterOptions) bool {
	desc := record["desc"].(string)
	severity := record["severity"].(string)
	node := record["node_id"].(string)
	typ := record["type"].(string)
	process := record["process"].(string)

	if len(options.NodeID) > 0 && node != options.NodeID {
		return false
	}

	if !options.NoColor {
		record["node_id"] = golor.Colorize(node, golor.GRAY, -1)
		record["Type"] = golor.Colorize(typ, golor.MAGENTA, -1)
		record["process"] = golor.Colorize(process, golor.BLUE, -1)
		switch severity {
		case "ERROR":
			record["desc"] = golor.Colorize(desc, -1, golor.RED)
		case "WARNING":
			record["desc"] = golor.Colorize(desc, 0, golor.YELLOW)
		default:
		}
	}
	return true
}
Esempio n. 2
0
func (p MessagePrinter) PrintInternalError(errmsg string) {
	if p.options.NoColor {
		fmt.Println(errmsg)
	} else {
		fmt.Printf("%v: %v\n",
			golor.Colorize("INTERNAL", golor.WHITE, golor.RED),
			golor.Colorize(errmsg, golor.RED, -1))
	}
}
Esempio n. 3
0
func handleApptail(record map[string]interface{}, options MessagePrinterOptions) bool {
	appname := record["app_name"].(string)
	node := record["node_id"].(string)

	if len(options.NodeID) > 0 && node != options.NodeID {
		return false
	}

	if !options.NoColor {
		record["node_id"] = golor.Colorize(node, golor.GRAY, -1)
		record["app_name"] = golor.Colorize(appname, golor.BLUE, -1)
	}
	return true
}
Esempio n. 4
0
func printStatus(name, nodeip string, info statecache.StateInfo) error {
	rev, err := strconv.Atoi(info["rev"])
	if err != nil {
		return fmt.Errorf("Corrupt drain status: %v", err)
	}
	state := info["name"]

	fmt.Printf("%-20s\t%s\t%s[%d]", name, nodeip, state, rev)
	if error, ok := info["error"]; ok {
		fmt.Printf("\t%s", golor.Colorize(error, golor.RGB(5, 0, 0), -1))
	}
	fmt.Println()
	return nil
}
Esempio n. 5
0
// Print a message from logyard streams
func (p MessagePrinter) Print(msg zmqpubsub.Message) error {
	if p.options.JSON {
		key, value := msg.Key, msg.Value
		if !p.options.NoColor {
			key = golor.Colorize(msg.Key, golor.RGB(0, 4, 4), -1)
		}
		fmt.Printf("%s %s\n", key, value)
		return nil
	}

	// TODO: somehow use {apptail,systail}.Message and {sieve}.Event here.
	var record map[string]interface{}

	if err := json.Unmarshal([]byte(msg.Value), &record); err != nil {
		p.PrintInternalError(fmt.Sprintf(
			"ERROR decoding json from message (key '%v'): %v",
			msg.Key, msg.Value))
		return nil
	}

	key := msg.Key
	if strings.Contains(key, ".") {
		key = strings.SplitN(key, ".", 2)[0]
	}

	if tmpl, ok := p.templates[key]; ok {
		var buf bytes.Buffer

		if p.filterFn(key, record, p.options) {
			if err := tmpl.Execute(&buf, record); err != nil {
				return err
			}
			s := string(buf.Bytes())
			if p.options.ShowTime {
				s = fmt.Sprintf("%s %s", time.Now(), s)
			}
			fmt.Println(s)
		}
		return nil
	}
	return fmt.Errorf("no format added for key: %s", key)
}
Esempio n. 6
0
func main() {
	fmt.Println("# Printing 16 colors ...")
	fmt.Println(golor.Colorize("GRAY", golor.GRAY, -1))
	fmt.Println(golor.Colorize("RED", golor.R, -1))
	fmt.Println(golor.Colorize("GREEN", golor.G, -1))
	fmt.Println(golor.Colorize("BLUE", golor.BLUE, -1))
	fmt.Println(golor.Colorize("MAGENTA", golor.M, -1))
	fmt.Println(golor.Colorize("YELLOW", golor.Y, -1))
	fmt.Println(golor.Colorize("CYAN", golor.C, -1))
	fmt.Println(golor.Colorize("BLACK", golor.BLACK, golor.WHITE))
	fmt.Println(golor.Colorize("WHITE", golor.WHITE, -1))
	fmt.Println(golor.Colorize("LOWEST", golor.RGB(0, 0, 0), golor.WHITE))
	fmt.Println(golor.Colorize("HIGHEST", golor.RGB(5, 5, 5), -1))
	// fmt.Println(golor.Colorize("TEST", 16, -1))
	fmt.Println("# Now printing 256 colors ...")
	time.Sleep(time.Second)
	for i := 255; i >= 0; i-- {
		fmt.Println(golor.Colorize("Foreground", i, -1))
		fmt.Println(golor.Colorize("Background", -1, i))
	}
}
Esempio n. 7
0
func main() {
	fmt.Println("# Consistently assigning unique colors to strings:")
	for _, ape := range getScientificApes() {
		fmt.Println(golor.Colorize(ape, golor.AssignColor(ape), -1))
	}
}
Esempio n. 8
0
func handleSystail(record map[string]interface{}, options MessagePrinterOptions) bool {
	text := record["text"].(string)
	process := record["name"].(string)
	node := record["node_id"].(string)
	severity := ""

	if len(options.NodeID) > 0 && node != options.NodeID {
		return false
	}

	if !options.LogyardVerbose && process == "logyard" && strings.Contains(text, "INFO") {
		return false
	}

	// TODO: hide ip addr in micro cloud.

	if strings.Contains(process, "nginx") {
		// FIXME: nginx logs reflect requests to not only vcap
		// processes (eg: cc and services), but also deployed
		// apps. the purpose of `kato tail` is to tail the log of
		// vcap and other core processes only, not the deployed
		// apps. perhaps we could redirect app requests to a
		// different log file?
		switch {
		case strings.Contains(text, "[error]"):
			severity = "ERROR"
		case strings.Contains(text, "No such file or directory"):
			fallthrough
		case strings.Contains(text, "404"):
			severity = "WARN"
		default:
		}
	} else {
		switch {
		case strings.Contains(text, "ERROR"):
			severity = "ERROR"
		case strings.Contains(text, "WARN"):
			severity = "WARN"
		default:
		}
	}

	// Strip non-essential data
	if !options.Raw {
		for _, re := range datetimePatterns {
			res := re.FindStringSubmatch(text)
			if len(res) > 1 {
				text = res[1]
				break
			}
		}
	}

	if !options.NoColor {
		record["node_id"] = golor.Colorize(node, golor.GRAY, -1)
		switch severity {
		case "ERROR":
			record["text"] = golor.Colorize(text, golor.RED, -1)
		case "WARN":
			// yellow
			record["text"] = golor.Colorize(text, golor.YELLOW, -1)
		default:
			record["text"] = text
		}

		// Assign an unique color to the process name
		record["name"] = golor.Colorize(process, golor.AssignColor(process), -1)
	}
	return true
}