//LogView displays the basic logs
func (handler LogServerHTTPHandler) LogView(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
	result, err := Influx.QueryDB(handler.influxClient, fmt.Sprintf("select time, event, msg, serveritry, source from %s", LogServer.TableName), Config.GetServerConfig().LogServer.InfluxDatabase)
	if err != nil {
		panic(err)
	}

	table := `<html><body><table style="width:100%"><tr>`
	for _, column := range result[0].Series[0].Columns {
		table += fmt.Sprintf(`<th>%s</th>`, column)
	}
	table += "</tr>"
	for _, row := range result[0].Series[0].Values {
		table += "<tr>"
		for i, field := range row {
			var output = fmt.Sprint(field)
			if i == 1 {
				u := r.URL
				u.Path = "/resend"
				parameters := url.Values{}
				parameters.Add(GETEVENTKEY, output)
				u.RawQuery = parameters.Encode()
				output = fmt.Sprintf(`<pre><a href="%s">%s</a></pre>`, u, Strings.FormatJSON(output))
			}
			table += fmt.Sprintf(`<td>%s</td>`, output)
		}
		table += "</tr>"
	}
	table += "</table></body></html>"

	io.WriteString(w, table)
}
Example #2
0
//NewLogServer constructs a new LogServer
func NewLogServer() *Server {
	var influxClient client.Client
	if Config.GetServerConfig().LogServer.InfluxAddress != "" {
		u, err := url.Parse(Config.GetServerConfig().LogServer.InfluxAddress)
		if err != nil {
			panic(err)
		}
		influxClient = client.NewClient(client.Config{
			URL:      u,
			Username: Config.GetServerConfig().LogServer.InfluxUsername,
			Password: Config.GetServerConfig().LogServer.InfluxPassword,
		})
		_, err = Influx.QueryDB(influxClient, fmt.Sprintf("CREATE DATABASE %s", Config.GetServerConfig().LogServer.InfluxDatabase), Config.GetServerConfig().LogServer.InfluxDatabase)
		if err != nil {
			panic(err)
		}
	}
	return &Server{LogQueue: make(chan LogMessage, 100), quit: make(chan bool), isRunning: false, InfluxClient: influxClient}
}