mirror of
https://github.com/containers/podman.git
synced 2025-10-13 17:26:13 +08:00
Add event logging to libpod, even display to podman
In lipod, we now log major events that occurr. These events can be displayed using the `podman events` command. Each event contains: * Type (container, image, volume, pod...) * Status (create, rm, stop, kill, ....) * Timestamp in RFC3339Nano format * Name (if applicable) * Image (if applicable) The format of the event and the varlink endpoint are to not be considered stable until cockpit has done its enablement. Signed-off-by: baude <bbaude@redhat.com>
This commit is contained in:
56
pkg/varlinkapi/events.go
Normal file
56
pkg/varlinkapi/events.go
Normal file
@ -0,0 +1,56 @@
|
||||
package varlinkapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/containers/libpod/cmd/podman/shared"
|
||||
"github.com/containers/libpod/cmd/podman/varlink"
|
||||
"github.com/containers/libpod/libpod/events"
|
||||
)
|
||||
|
||||
// GetEvents is a remote endpoint to get events from the event log
|
||||
func (i *LibpodAPI) GetEvents(call iopodman.VarlinkCall, filter []string, since string, stream bool, until string) error {
|
||||
var (
|
||||
fromStart bool
|
||||
eventsError error
|
||||
event *events.Event
|
||||
)
|
||||
if call.WantsMore() {
|
||||
call.Continues = true
|
||||
}
|
||||
filters, err := shared.GenerateEventOptions(filter, since, until)
|
||||
if err != nil {
|
||||
return call.ReplyErrorOccurred(err.Error())
|
||||
}
|
||||
if len(since) > 0 || len(until) > 0 {
|
||||
fromStart = true
|
||||
}
|
||||
eventChannel := make(chan *events.Event)
|
||||
go func() {
|
||||
eventsError = i.Runtime.Events(fromStart, stream, filters, eventChannel)
|
||||
}()
|
||||
if eventsError != nil {
|
||||
return call.ReplyErrorOccurred(err.Error())
|
||||
}
|
||||
for {
|
||||
event = <-eventChannel
|
||||
if event == nil {
|
||||
call.Continues = false
|
||||
break
|
||||
}
|
||||
call.ReplyGetEvents(iopodman.Event{
|
||||
Id: event.ID,
|
||||
Image: event.Image,
|
||||
Name: event.Name,
|
||||
Status: fmt.Sprintf("%s", event.Status),
|
||||
Time: event.Time.Format(time.RFC3339Nano),
|
||||
Type: fmt.Sprintf("%s", event.Type),
|
||||
})
|
||||
if !call.Continues {
|
||||
// For a one-shot on events, we break out here
|
||||
break
|
||||
}
|
||||
}
|
||||
return call.ReplyGetEvents(iopodman.Event{})
|
||||
}
|
Reference in New Issue
Block a user