kaginawa

package module
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2022 License: BSD-3-Clause Imports: 24 Imported by: 0

README

kaginawa-server

Actions Status Actions Status Quality Gate Status Go Report Card

Deploy

Kaginawa server program.

See kaginawa repository for more details.

Docker image is available at Docker Hub.

Requirements

OAuth 2.0 Provider

Administration users must be authorized by OAuth 2.0 provider.

You can choose Auth0, Google and more as an identity provider.

Using Auth0

Required environment variables:

  • AUTH0_DOMAIN - OAuth 2.0 provider domain name (e.g. xxx.auth0.com)
  • AUTH0_CLIENT_ID - OAuth 2.0 provider client ID
  • AUTH0_CLIENT_SECRET - OAuth 2.0 provider client secret
  • SELF_URL - Self URL using OAuth 2.0 callback process (e.g. http://localhost:8080)

If you use the [Deploy to Heroku] button, they will be set automatically by the add-on except SELF_URL.

Using Google OAuth 2.0 API

Required environment variables:

  • OAUTH_TYPE - Set to google
  • OAUTH_CLIENT_ID - OAuth 2.0 provider client ID
  • OAUTH_CLIENT_SECRET - OAuth 2.0 provider client secret
  • SELF_URL - Self URL using OAuth 2.0 callback process (e.g. http://localhost:8080)

See developer.google.com for more information.

Using other identity providers

Required environment variables:

  • OAUTH_TYPE - Set to custom
  • OAUTH_CLIENT_ID - OAuth 2.0 provider client ID
  • OAUTH_CLIENT_SECRET - OAuth 2.0 provider client secret
  • SELF_URL - Self URL using OAuth 2.0 callback process (e.g. http://localhost:8080)
  • OAUTH_AUTH_URL - OAuth 2.0 authorization URL
  • OAUTH_TOKEN_URL - OAuth 2.0 token URL
  • OAUTH_AUDIENCE - OAuth 2.0 audience string
  • OAUTH_USERINFO_URL - OpenID Connect user info URL
Database

You can choose MongoDB or DynamoDB as a database.

Using MongoDB

Required environment variable:

  • MONGODB_URI: MongoDB endpoint (mongodb://user:pass@host:port/db)

Note that MongoDB Atlas may fail to connect with long database name, so exclude all parameters from the connection string (e.g. mongodb+srv://user:pass@cluster/db).

Kaginawa Server automatically creates following collections when first touch:

  • keys - All API keys
  • servers - All SSH servers
  • nodes - Newest received reports for each node
  • logs - All received reports (*1)
  • sessions - Web UI sessions (*2)

*1) We recommend creating logs collection as a capped collection. Example mongo shell (set to 256 MB):

db.runCommand({"convertToCapped": "logs", size: 268435456})

*2) Session expiration is configurable with TTL indexes feature. Example mongo shell (set to 6 months):

db.sessions.createIndex({"time": 1}, {expireAfterSeconds: 15552000})
Using DynamoDB

Kaginawa server uses AWS default credentials. See the comment of AWS SDK for Go API Reference for more details.

Required environment variables:

  • DYNAMO_KEYS - Table of keys (e.g. KaginawaKeys)
  • DYNAMO_SERVERS - Table of servers (e.g. KaginawaServers)
  • DYNAMO_NODES - Table of nodes (e.g. KaginawaNodes)
  • DYNAMO_LOGS - Table of logs (e.g. KaginawaLogs)
  • DYNAMO_SESSIONS = Table of sessions (e.g. KaginawaSessions)
  • DYNAMO_CUSTOM_IDS - Index of custom id (e.g. CustomID-index)
  • DYNAMO_LOGS_TTL_DAYS - (Optional) TTL for the table of logs
  • DYNAMO_SESSIONS_TTL_DAYS - (Optional) TTL for the table of sessions
  • DYNAMO_ENDPOINT - (Optional) Custom endpoint (i.e. using DynamoDB Local)

Create a table of keys using aws-cli:

aws dynamodb create-table \
    --table-name KaginawaKeys \
    --attribute-definitions AttributeName=Key,AttributeType=S \
    --key-schema AttributeName=Key,KeyType=HASH \
    --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1

Create a table of servers using aws-cli:

aws dynamodb create-table \
    --table-name KaginawaServers \
    --attribute-definitions AttributeName=Host,AttributeType=S \
    --key-schema AttributeName=Host,KeyType=HASH \
    --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1

Create a table of nodes using aws-cli:

aws dynamodb create-table \
    --table-name KaginawaNodes \
    --attribute-definitions AttributeName=ID,AttributeType=S \
    --key-schema AttributeName=ID,KeyType=HASH \
    --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1

Create a table of logs using aws-cli:

aws dynamodb create-table \
    --table-name KaginawaLogs \
    --attribute-definitions \
        AttributeName=ID,AttributeType=S \
        AttributeName=ServerTime,AttributeType=N \
    --key-schema AttributeName=ID,KeyType=HASH AttributeName=ServerTime,KeyType=RANGE \
    --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1
aws dynamodb update-time-to-live \
    --table-name KaginawaLogs \
    --time-to-live-specification \
        Enabled=true,AttributeName=TTL

Create a table of sessions using aws-cli:

aws dynamodb create-table \
    --table-name KaginawaSessions \
    --attribute-definitions AttributeName=ID,AttributeType=S \
    --key-schema AttributeName=ID,KeyType=HASH \
    --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1
aws dynamodb update-time-to-live \
    --table-name KaginawaSessions \
    --time-to-live-specification \
        Enabled=true,AttributeName=TTL

Create an index of custom ID for a table of nodes using aws-cli:

aws dynamodb update-table \
    --table-name KaginawaNodes \
    --attribute-definitions AttributeName=CustomID,AttributeType=S \
    --global-secondary-index-updates \
    "[{\"Create\":{\"IndexName\": \"CustomID-index\",\"KeySchema\":[{\"AttributeName\":\"CustomID\",\"KeyType\":\"HASH\"}], \
    \"ProvisionedThroughput\": {\"ReadCapacityUnits\": 1, \"WriteCapacityUnits\": 1},\"Projection\":{\"ProjectionType\":\"ALL\"}}}]" 

Admin API

/nodes List nodes
  • Method: GET
  • Resource: /nodes
  • Query Params:
    • (Optional) custom-id - filter by custom-id
    • (Optional) minutes - filter by minutes ago
    • (Optional) projection - pattern of projection attributes (all, id, list-view or measurement)
  • Headers:
    • Authorization: token <admin_api_key>
    • Accept: application/json
  • Response: List of all Record object (see db.go definition)

Curl example with no query params:

curl -H "Authorization: token admin123" -H "Accept: application/json" -X GET "http://localhost:8080/nodes"

Curl example with custom-id:

curl -H "Authorization: token admin123" -H "Accept: application/json" -X GET "http://localhost:8080/nodes?custom-id=dev1"

NOTE: Custom IDs are expect to unique, but can be duplicated (such as device replacements).

Curl example with custom-id and minutes:

curl -H "Authorization: token admin123" -H "Accept: application/json" -X GET "http://localhost:8080/nodes?custom-id=dev1&minutes=5"

Curl example with minutes and projection:

curl -H "Authorization: token admin123" -H "Accept: application/json" -X GET "http://localhost:8080/nodes?minutes=5&projection=id"
/nodes/:id Get node by ID
  • Method: GET
  • Resource: /nodes/:id
  • Headers:
    • Authorization: token <admin_api_key>
    • Accept: application/json
  • Response: A Record object (see db.go definition)

Curl example:

curl -H "Authorization: token admin123" -H "Accept: application/json" -X GET "http://localhost:8080/nodes/02:00:17:00:7d:b0"
/nodes/:id/command Send command via ssh
  • Method: POST
  • Resource: /nodes/:id/command
  • Header:
    • Authorization: token <admin_api_key>
  • Form params:
    • command - command
    • user - ssh user name
    • (Optional) key - ssh private key
    • (Optional) password - ssh password
    • (Optional) timeout - timeout seconds (default: 30)
  • Response: Command result (MIME: text/plain)

Curl example:

curl -H "Authorization: token admin123" -X POST -d user=pi -d password=raspberry -d timeout=10 -d command="ls -alh" "http://localhost:8080/nodes/02:00:17:00:7d:b0/command"
/nodes/:id/histories List report histories
  • Method: GET
  • Resource: /nodes/:id/history
  • Header:
    • Authorization: token <admin_api_key>
  • Form params:
    • (Optional) begin - begin time as UTC unix timestamp (default: 24 hours ago)
    • (Optional) end - end time as UTC unix timestamp (default: now)
    • (Optional) projection - pattern of projection attributes (all, id, list-view or measurement)
  • Response: List of all Record object (see db.go definition)

Curl example:

curl -H "Authorization: token admin123" -H "Accept: application/json" -X GET "http://localhost:8080/nodes/02:00:17:00:7d:b0/history&begin=1581900000&end=1582000000"

License

Kaginawa Server licensed under the BSD 3-clause license.

Author

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// KnownAPIKeys caches known api keys on memory.
	KnownAPIKeys sync.Map
	// KnownAdminAPIKeys caches known admin api keys on memory.
	KnownAdminAPIKeys sync.Map
	// SSHServers caches list of ssh servers on memory.
	SSHServers []SSHServer
)

Functions

This section is empty.

Types

type APIKey

type APIKey struct {
	Key   string `bson:"key"`
	Label string `bson:"label"`
	Admin bool   `bson:"admin"`
}

APIKey defines database item of an api key.

type DB

type DB interface {
	// ValidateAPIKey validates API key. Results are ok, label and error.
	ValidateAPIKey(key string) (bool, string, error)
	// ValidateAdminAPIKey validates API key for admin privilege only. Results are ok, label and error.
	ValidateAdminAPIKey(key string) (bool, string, error)
	// ListAPIKeys scans all api keys.
	ListAPIKeys() ([]APIKey, error)
	// PutAPIKey puts an api key.
	PutAPIKey(apiKey APIKey) error
	// ListSSHServers scans all ssh servers.
	ListSSHServers() ([]SSHServer, error)
	// GetSSHServerByHost queries a server by host.
	GetSSHServerByHost(host string) (*SSHServer, error)
	// PutSSHServer puts a ssh server entry.
	PutSSHServer(server SSHServer) error
	// PutReport puts a report.
	PutReport(report Report) error
	// CountReports counts number of reports.
	CountReports() (int, error)
	// ListReports scans list of reports.
	ListReports(skip, limit, minutes int, projection Projection) ([]Report, error)
	// CountAndListReports scans list of reports with total count.
	CountAndListReports(skip, limit, minutes int, projection Projection) ([]Report, int, error)
	// GetReportByID queries a report by id. Returns (nil, nil) if not found.
	GetReportByID(id string) (*Report, error)
	// ListReportsByCustomID queries list of reports by custom id.
	ListReportsByCustomID(customID string, minutes int, projection Projection) ([]Report, error)
	// DeleteReport deletes a report. Histories are preserved.
	DeleteReport(id string) error
	// ListHistory queries list of history.
	ListHistory(id string, begin time.Time, end time.Time, projection Projection) ([]Report, error)
	// GetUserSession gets a user session.
	GetUserSession(id string) (*UserSession, error)
	// PutUserSession puts a user session.
	PutUserSession(session UserSession) error
	// DeleteUserSession deletes a user session.
	DeleteUserSession(id string) error
}

DB implements database operations.

type DynamoDB

type DynamoDB struct {
	// contains filtered or unexported fields
}

DynamoDB implements DB interface.

func NewDynamoDB

func NewDynamoDB() (*DynamoDB, error)

NewDynamoDB will creates AWS DynamoDB instance that implements DB interface.

func (*DynamoDB) CountAndListReports added in v0.0.3

func (db *DynamoDB) CountAndListReports(skip, limit, minutes int, projection Projection) ([]Report, int, error)

CountAndListReports implements same signature of the DB interface.

func (*DynamoDB) CountReports

func (db *DynamoDB) CountReports() (int, error)

CountReports implements same signature of the DB interface.

func (*DynamoDB) DeleteReport added in v0.1.1

func (db *DynamoDB) DeleteReport(id string) error

DeleteReport implements same signature of the DB interface.

func (*DynamoDB) DeleteUserSession added in v0.1.0

func (db *DynamoDB) DeleteUserSession(id string) error

DeleteUserSession implements same signature of the DB interface.

func (*DynamoDB) GetReportByID

func (db *DynamoDB) GetReportByID(id string) (*Report, error)

GetReportByID implements same signature of the DB interface.

func (*DynamoDB) GetSSHServerByHost

func (db *DynamoDB) GetSSHServerByHost(host string) (*SSHServer, error)

GetSSHServerByHost implements same signature of the DB interface.

func (*DynamoDB) GetUserSession added in v0.1.0

func (db *DynamoDB) GetUserSession(id string) (*UserSession, error)

GetUserSession implements same signature of the DB interface.

func (*DynamoDB) ListAPIKeys

func (db *DynamoDB) ListAPIKeys() ([]APIKey, error)

ListAPIKeys implements same signature of the DB interface.

func (*DynamoDB) ListHistory added in v0.0.3

func (db *DynamoDB) ListHistory(id string, begin time.Time, end time.Time, projection Projection) ([]Report, error)

ListHistory implements same signature of the DB interface.

func (*DynamoDB) ListReports

func (db *DynamoDB) ListReports(skip, limit, minutes int, projection Projection) ([]Report, error)

ListReports implements same signature of the DB interface. Set limit <= 0 to enable unlimited scans.

func (*DynamoDB) ListReportsByCustomID

func (db *DynamoDB) ListReportsByCustomID(customID string, minutes int, projection Projection) ([]Report, error)

ListReportsByCustomID implements same signature of the DB interface.

func (*DynamoDB) ListSSHServers

func (db *DynamoDB) ListSSHServers() ([]SSHServer, error)

ListSSHServers implements same signature of the DB interface.

func (*DynamoDB) PutAPIKey

func (db *DynamoDB) PutAPIKey(apiKey APIKey) error

PutAPIKey implements same signature of the DB interface.

func (*DynamoDB) PutReport

func (db *DynamoDB) PutReport(report Report) error

PutReport implements same signature of the DB interface.

func (*DynamoDB) PutSSHServer

func (db *DynamoDB) PutSSHServer(server SSHServer) error

PutSSHServer implements same signature of the DB interface.

func (*DynamoDB) PutUserSession added in v0.1.0

func (db *DynamoDB) PutUserSession(session UserSession) error

PutUserSession implements same signature of the DB interface.

func (*DynamoDB) SessionTTLSeconds added in v0.1.0

func (db *DynamoDB) SessionTTLSeconds() int

SessionTTLSeconds calculates session TTL seconds.

func (*DynamoDB) ValidateAPIKey

func (db *DynamoDB) ValidateAPIKey(key string) (bool, string, error)

ValidateAPIKey implements same signature of the DB interface.

func (*DynamoDB) ValidateAdminAPIKey

func (db *DynamoDB) ValidateAdminAPIKey(key string) (bool, string, error)

ValidateAdminAPIKey implements same signature of the DB interface.

type MemDB

type MemDB struct {
	// contains filtered or unexported fields
}

MemDB implements in-memory store for testing.

func NewMemDB

func NewMemDB() *MemDB

NewMemDB will creates in-memory DB instance that implements DB interface.

func (*MemDB) CountAndListReports added in v0.0.3

func (db *MemDB) CountAndListReports(skip, limit, _ int, _ Projection) ([]Report, int, error)

CountAndListReports implements same signature of the DB interface.

func (*MemDB) CountReports

func (db *MemDB) CountReports() (int, error)

CountReports implements same signature of the DB interface.

func (*MemDB) DeleteReport added in v0.1.1

func (db *MemDB) DeleteReport(id string) error

DeleteReport implements same signature of the DB interface.

func (*MemDB) DeleteUserSession added in v0.1.0

func (db *MemDB) DeleteUserSession(id string) error

DeleteUserSession implements same signature of the DB interface.

func (*MemDB) GetReportByID

func (db *MemDB) GetReportByID(id string) (*Report, error)

GetReportByID implements same signature of the DB interface.

func (*MemDB) GetSSHServerByHost

func (db *MemDB) GetSSHServerByHost(host string) (*SSHServer, error)

GetSSHServerByHost implements same signature of the DB interface.

func (*MemDB) GetUserSession added in v0.1.0

func (db *MemDB) GetUserSession(id string) (*UserSession, error)

GetUserSession implements same signature of the DB interface.

func (*MemDB) ListAPIKeys

func (db *MemDB) ListAPIKeys() ([]APIKey, error)

ListAPIKeys implements same signature of the DB interface.

func (*MemDB) ListHistory added in v0.0.3

func (db *MemDB) ListHistory(id string, begin time.Time, end time.Time, _ Projection) ([]Report, error)

ListHistory implements same signature of the DB interface.

func (*MemDB) ListReports

func (db *MemDB) ListReports(skip, limit, _ int, _ Projection) ([]Report, error)

ListReports implements same signature of the DB interface.

func (*MemDB) ListReportsByCustomID

func (db *MemDB) ListReportsByCustomID(customID string, _ int, _ Projection) ([]Report, error)

ListReportsByCustomID implements same signature of the DB interface.

func (*MemDB) ListSSHServers

func (db *MemDB) ListSSHServers() ([]SSHServer, error)

ListSSHServers implements same signature of the DB interface.

func (*MemDB) PutAPIKey

func (db *MemDB) PutAPIKey(apiKey APIKey) error

PutAPIKey implements same signature of the DB interface.

func (*MemDB) PutReport

func (db *MemDB) PutReport(report Report) error

PutReport implements same signature of the DB interface.

func (*MemDB) PutSSHServer

func (db *MemDB) PutSSHServer(server SSHServer) error

PutSSHServer implements same signature of the DB interface.

func (*MemDB) PutUserSession added in v0.1.0

func (db *MemDB) PutUserSession(session UserSession) error

PutUserSession implements same signature of the DB interface.

func (*MemDB) ValidateAPIKey

func (db *MemDB) ValidateAPIKey(key string) (bool, string, error)

ValidateAPIKey implements same signature of the DB interface.

func (*MemDB) ValidateAdminAPIKey

func (db *MemDB) ValidateAdminAPIKey(key string) (bool, string, error)

ValidateAdminAPIKey implements same signature of the DB interface.

type MongoDB

type MongoDB struct {
	// contains filtered or unexported fields
}

MongoDB implements DB interface.

func NewMongoDB

func NewMongoDB(endpoint string) (*MongoDB, error)

NewMongoDB will creates MongoDB instance that implements DB interface.

func (*MongoDB) CountAndListReports added in v0.0.3

func (db *MongoDB) CountAndListReports(skip, limit, minutes int, projection Projection) ([]Report, int, error)

CountAndListReports implements same signature of the DB interface.

func (*MongoDB) CountReports

func (db *MongoDB) CountReports() (int, error)

CountReports counts number of records in node table.

func (*MongoDB) DeleteReport added in v0.1.1

func (db *MongoDB) DeleteReport(id string) error

DeleteReport implements same signature of the DB interface.

func (*MongoDB) DeleteUserSession added in v0.1.0

func (db *MongoDB) DeleteUserSession(id string) error

DeleteUserSession implements same signature of the DB interface.

func (*MongoDB) GetReportByID

func (db *MongoDB) GetReportByID(id string) (*Report, error)

GetReportByID implements same signature of the DB interface.

func (*MongoDB) GetSSHServerByHost

func (db *MongoDB) GetSSHServerByHost(host string) (*SSHServer, error)

GetSSHServerByHost implements same signature of the DB interface.

func (*MongoDB) GetUserSession added in v0.1.0

func (db *MongoDB) GetUserSession(id string) (*UserSession, error)

GetUserSession implements same signature of the DB interface.

func (*MongoDB) ListAPIKeys

func (db *MongoDB) ListAPIKeys() ([]APIKey, error)

ListAPIKeys implements same signature of the DB interface.

func (*MongoDB) ListHistory added in v0.0.3

func (db *MongoDB) ListHistory(id string, begin time.Time, end time.Time, projection Projection) ([]Report, error)

ListHistory implements same signature of the DB interface.

func (*MongoDB) ListReports

func (db *MongoDB) ListReports(skip, limit, minutes int, projection Projection) ([]Report, error)

ListReports implements same signature of the DB interface.

func (*MongoDB) ListReportsByCustomID

func (db *MongoDB) ListReportsByCustomID(customID string, minutes int, projection Projection) ([]Report, error)

ListReportsByCustomID implements same signature of the DB interface.

func (*MongoDB) ListSSHServers

func (db *MongoDB) ListSSHServers() ([]SSHServer, error)

ListSSHServers implements same signature of the DB interface.

func (*MongoDB) PutAPIKey

func (db *MongoDB) PutAPIKey(apiKey APIKey) error

PutAPIKey implements same signature of the DB interface.

func (*MongoDB) PutReport

func (db *MongoDB) PutReport(report Report) error

PutReport implements same signature of the DB interface.

func (*MongoDB) PutSSHServer

func (db *MongoDB) PutSSHServer(server SSHServer) error

PutSSHServer implements same signature of the DB interface.

func (*MongoDB) PutUserSession added in v0.1.0

func (db *MongoDB) PutUserSession(session UserSession) error

PutUserSession implements same signature of the DB interface.

func (*MongoDB) ValidateAPIKey

func (db *MongoDB) ValidateAPIKey(key string) (bool, string, error)

ValidateAPIKey implements same signature of the DB interface.

func (*MongoDB) ValidateAdminAPIKey

func (db *MongoDB) ValidateAdminAPIKey(key string) (bool, string, error)

ValidateAdminAPIKey implements same signature of the DB interface.

type Projection

type Projection int

Projection defines parameter patterns of projection attributes

const (
	// AllAttributes defines projection pattern of all attributes
	AllAttributes Projection = iota
	// IDAttributes defines projection pattern of ID attributes
	IDAttributes
	// ListViewAttributes defines projection pattern of list page attributes
	ListViewAttributes
	// MeasurementAttributes defines projection pattern of measurement attributes
	MeasurementAttributes
)

type Report

type Report struct {
	// Kaginawa shared fields
	ID             string      `json:"id" bson:"id"`                                       // MAC address
	Trigger        int         `json:"trigger,omitempty" bson:"trigger"`                   // Report trigger (-1/0/n)
	Runtime        string      `json:"runtime,omitempty" bson:"runtime"`                   // OS and arch
	Success        bool        `json:"success" bson:"success"`                             // Equals len(Errors) == 0
	Sequence       int         `json:"seq,omitempty" bson:"seq"`                           // Report sequence number
	DeviceTime     int64       `json:"device_time,omitempty" bson:"device_time"`           // Device time (UTC)
	BootTime       int64       `json:"boot_time,omitempty" bson:"boot_time"`               // Device boot time (UTC)
	GenMillis      int64       `json:"gen_ms,omitempty" bson:"gen_ms"`                     // Generation time millis
	AgentVersion   string      `json:"agent_version,omitempty" bson:"agent_version"`       // Agent version
	CustomID       string      `json:"custom_id,omitempty" bson:"custom_id"`               // User specified ID
	SSHServerHost  string      `json:"ssh_server_host,omitempty" bson:"ssh_server_host"`   // Connected SSH server host
	SSHRemotePort  int         `json:"ssh_remote_port,omitempty" bson:"ssh_remote_port"`   // Connected SSH remote port
	SSHConnectTime int64       `json:"ssh_connect_time,omitempty" bson:"ssh_connect_time"` // Connected time of the SSH
	Adapter        string      `json:"adapter,omitempty" bson:"adapter"`                   // Name of network adapter
	LocalIPv4      string      `json:"ip4_local,omitempty" bson:"ip4_local"`               // Local IPv6 address
	LocalIPv6      string      `json:"ip6_local,omitempty" bson:"ip6_local"`               // Local IPv6 address
	Hostname       string      `json:"hostname,omitempty" bson:"hostname"`                 // OS Hostname
	RTTMills       int64       `json:"rtt_ms,omitempty" bson:"rtt_ms"`                     // Round trip time millis
	UploadKBPS     int64       `json:"upload_bps,omitempty" bson:"upload_bps"`             // Upload throughput bps
	DownloadKBPS   int64       `json:"download_bps,omitempty" bson:"download_bps"`         // Download throughput bps
	DiskTotalBytes int64       `json:"disk_total_bytes,omitempty" bson:"disk_total_bytes"` // Total disk space (Bytes)
	DiskUsedBytes  int64       `json:"disk_used_bytes,omitempty" bson:"disk_used_bytes"`   // Used disk space (Bytes)
	DiskLabel      string      `json:"disk_label,omitempty" bson:"disk_label"`             // Disk label
	DiskFilesystem string      `json:"disk_filesystem,omitempty" bson:"disk_filesystem"`   // Disk filesystem name
	DiskMountPoint string      `json:"disk_mount_point,omitempty" bson:"disk_mount_point"` // Mount point (default is /)
	DiskDevice     string      `json:"disk_device,omitempty" bson:"disk_device"`           // Disk device name
	USBDevices     []USBDevice `json:"usb_devices,omitempty" bson:"usb_devices"`           // List of usb devices
	BDLocalDevices []string    `json:"bd_local_devices,omitempty" bson:"bd_local_devices"` // List of BT local devices
	KernelVersion  string      `json:"kernel_version,omitempty" bson:"kernel_version"`     // Kernel version
	Errors         []string    `json:"errors,omitempty" bson:"errors"`                     // List of errors
	Payload        string      `json:"payload,omitempty" bson:"payload"`                   // Custom content
	PayloadCmd     string      `json:"payload_cmd,omitempty" bson:"payload_cmd"`           // Executed payload command

	// Server-side injected fields
	GlobalIP   string    `json:"ip_global,omitempty" bson:"ip_global"`     // Global IP address
	GlobalHost string    `json:"host_global,omitempty" bson:"host_global"` // Reverse lookup result for global IP address
	ServerTime int64     `json:"server_time" bson:"server_time"`           // Server-side consumed UTC time
	APIKey     string    `json:"api_key,omitempty" bson:"api_key"`         // Used api key
	TTL        time.Time `json:"-" bson:"-" dynamodbav:",unixtime"`        // DynamoDB TTL
}

Report defines all of Report attributes

func MatchReports added in v0.0.3

func MatchReports(db DB, minutes int, projection Projection, matcher func(r Report) bool) ([]Report, error)

MatchReports generates list of reports filtered by specified matcher function.

func SubReports added in v0.0.3

func SubReports(reports []Report, skip, limit int) (sub []Report)

SubReports generates subsets of source reports.

func (Report) DiskUsageAsPercentage

func (r Report) DiskUsageAsPercentage() string

DiskUsageAsPercentage calculates disk usage as percentage.

func (Report) DownloadMBPS

func (r Report) DownloadMBPS() string

DownloadMBPS formats download throughput as Mbps.

func (Report) IsBootTimeReport

func (r Report) IsBootTimeReport() bool

IsBootTimeReport checks report triggered by boot time or not.

func (Report) IsIntervalReport

func (r Report) IsIntervalReport() bool

IsIntervalReport checks report triggered by interval timer or not.

func (Report) IsSSHConnectedReport

func (r Report) IsSSHConnectedReport() bool

IsSSHConnectedReport checks report triggered by ssh connected or not.

func (Report) UploadMBPS

func (r Report) UploadMBPS() string

UploadMBPS formats upload throughput as Mbps.

type SSHServer

type SSHServer struct {
	Host     string `json:"host" bson:"host"`
	Port     int    `json:"port" bson:"port"`
	User     string `json:"user" bson:"user"`
	Key      string `json:"key,omitempty" bson:"key"`
	Password string `json:"password,omitempty" bson:"password"`
}

SSHServer defines database item of a ssh server.

func (SSHServer) Addr

func (s SSHServer) Addr() string

Addr formats address by host:port.

type SessionStore added in v0.1.0

type SessionStore struct {
	// contains filtered or unexported fields
}

SessionStore implements gorilla/sessions sessions.Store.

func NewSessionDB added in v0.1.0

func NewSessionDB(db DB, expireSec int) (*SessionStore, error)

NewSessionDB constructs a SessionStore instance.

func (*SessionStore) Get added in v0.1.0

func (s *SessionStore) Get(req *http.Request, name string) (*sessions.Session, error)

Get implements sessions.Store.Get method.

func (*SessionStore) New added in v0.1.0

func (s *SessionStore) New(req *http.Request, name string) (*sessions.Session, error)

New implements sessions.Store.New method.

func (*SessionStore) Save added in v0.1.0

func (s *SessionStore) Save(_ *http.Request, w http.ResponseWriter, session *sessions.Session) error

Save implements sessions.Store.Save method.

type USBDevice

type USBDevice struct {
	Name      string `json:"name,omitempty" bson:"name"`
	VendorID  string `json:"vendor_id,omitempty" bson:"vendor_id"`
	ProductID string `json:"product_id,omitempty" bson:"product_id"`
	Location  string `json:"location,omitempty" bson:"location"`
}

USBDevice defines usb device information

type UserSession added in v0.1.0

type UserSession struct {
	ID      string           `bson:"sid"`
	Values  string           `bson:"values"` // encoded map[interface{}]interface{} using gob + base64
	Options sessions.Options `bson:"options"`
	Time    time.Time        `bson:"time" dynamodbav:"-"` // Used by MongoDB (TTL index)
	TTL     int64            `bson:"-"`                   // Used by DynamoDB (TTL attribute)
}

UserSession defines user session attributes.

func NewUserSession added in v0.1.0

func NewUserSession(session sessions.Session, ttl int64) (*UserSession, error)

NewUserSession will creates UserSession object.

func (UserSession) DecodeValues added in v0.1.0

func (s UserSession) DecodeValues() (map[interface{}]interface{}, error)

DecodeValues decodes raw values using gob.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL