Documentation ¶
Index ¶
- Variables
- type APIKey
- type DB
- type DynamoDB
- func (db *DynamoDB) CountAndListReports(skip, limit, minutes int, projection Projection) ([]Report, int, error)
- func (db *DynamoDB) CountReports() (int, error)
- func (db *DynamoDB) DeleteReport(id string) error
- func (db *DynamoDB) DeleteUserSession(id string) error
- func (db *DynamoDB) GetReportByID(id string) (*Report, error)
- func (db *DynamoDB) GetSSHServerByHost(host string) (*SSHServer, error)
- func (db *DynamoDB) GetUserSession(id string) (*UserSession, error)
- func (db *DynamoDB) ListAPIKeys() ([]APIKey, error)
- func (db *DynamoDB) ListHistory(id string, begin time.Time, end time.Time, projection Projection) ([]Report, error)
- func (db *DynamoDB) ListReports(skip, limit, minutes int, projection Projection) ([]Report, error)
- func (db *DynamoDB) ListReportsByCustomID(customID string, minutes int, projection Projection) ([]Report, error)
- func (db *DynamoDB) ListSSHServers() ([]SSHServer, error)
- func (db *DynamoDB) PutAPIKey(apiKey APIKey) error
- func (db *DynamoDB) PutReport(report Report) error
- func (db *DynamoDB) PutSSHServer(server SSHServer) error
- func (db *DynamoDB) PutUserSession(session UserSession) error
- func (db *DynamoDB) SessionTTLSeconds() int
- func (db *DynamoDB) ValidateAPIKey(key string) (bool, string, error)
- func (db *DynamoDB) ValidateAdminAPIKey(key string) (bool, string, error)
- type MemDB
- func (db *MemDB) CountAndListReports(skip, limit, _ int, _ Projection) ([]Report, int, error)
- func (db *MemDB) CountReports() (int, error)
- func (db *MemDB) DeleteReport(id string) error
- func (db *MemDB) DeleteUserSession(id string) error
- func (db *MemDB) GetReportByID(id string) (*Report, error)
- func (db *MemDB) GetSSHServerByHost(host string) (*SSHServer, error)
- func (db *MemDB) GetUserSession(id string) (*UserSession, error)
- func (db *MemDB) ListAPIKeys() ([]APIKey, error)
- func (db *MemDB) ListHistory(id string, begin time.Time, end time.Time, _ Projection) ([]Report, error)
- func (db *MemDB) ListReports(skip, limit, _ int, _ Projection) ([]Report, error)
- func (db *MemDB) ListReportsByCustomID(customID string, _ int, _ Projection) ([]Report, error)
- func (db *MemDB) ListSSHServers() ([]SSHServer, error)
- func (db *MemDB) PutAPIKey(apiKey APIKey) error
- func (db *MemDB) PutReport(report Report) error
- func (db *MemDB) PutSSHServer(server SSHServer) error
- func (db *MemDB) PutUserSession(session UserSession) error
- func (db *MemDB) ValidateAPIKey(key string) (bool, string, error)
- func (db *MemDB) ValidateAdminAPIKey(key string) (bool, string, error)
- type MongoDB
- func (db *MongoDB) CountAndListReports(skip, limit, minutes int, projection Projection) ([]Report, int, error)
- func (db *MongoDB) CountReports() (int, error)
- func (db *MongoDB) DeleteReport(id string) error
- func (db *MongoDB) DeleteUserSession(id string) error
- func (db *MongoDB) GetReportByID(id string) (*Report, error)
- func (db *MongoDB) GetSSHServerByHost(host string) (*SSHServer, error)
- func (db *MongoDB) GetUserSession(id string) (*UserSession, error)
- func (db *MongoDB) ListAPIKeys() ([]APIKey, error)
- func (db *MongoDB) ListHistory(id string, begin time.Time, end time.Time, projection Projection) ([]Report, error)
- func (db *MongoDB) ListReports(skip, limit, minutes int, projection Projection) ([]Report, error)
- func (db *MongoDB) ListReportsByCustomID(customID string, minutes int, projection Projection) ([]Report, error)
- func (db *MongoDB) ListSSHServers() ([]SSHServer, error)
- func (db *MongoDB) PutAPIKey(apiKey APIKey) error
- func (db *MongoDB) PutReport(report Report) error
- func (db *MongoDB) PutSSHServer(server SSHServer) error
- func (db *MongoDB) PutUserSession(session UserSession) error
- func (db *MongoDB) ValidateAPIKey(key string) (bool, string, error)
- func (db *MongoDB) ValidateAdminAPIKey(key string) (bool, string, error)
- type Projection
- type Report
- type SSHServer
- type SessionStore
- type USBDevice
- type UserSession
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
CountReports implements same signature of the DB interface.
func (*DynamoDB) DeleteReport ¶ added in v0.1.1
DeleteReport implements same signature of the DB interface.
func (*DynamoDB) DeleteUserSession ¶ added in v0.1.0
DeleteUserSession implements same signature of the DB interface.
func (*DynamoDB) GetReportByID ¶
GetReportByID implements same signature of the DB interface.
func (*DynamoDB) GetSSHServerByHost ¶
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 ¶
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 ¶
ListSSHServers implements same signature of the DB interface.
func (*DynamoDB) PutSSHServer ¶
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
SessionTTLSeconds calculates session TTL seconds.
func (*DynamoDB) ValidateAPIKey ¶
ValidateAPIKey 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
CountAndListReports implements same signature of the DB interface.
func (*MemDB) CountReports ¶
CountReports implements same signature of the DB interface.
func (*MemDB) DeleteReport ¶ added in v0.1.1
DeleteReport implements same signature of the DB interface.
func (*MemDB) DeleteUserSession ¶ added in v0.1.0
DeleteUserSession implements same signature of the DB interface.
func (*MemDB) GetReportByID ¶
GetReportByID implements same signature of the DB interface.
func (*MemDB) GetSSHServerByHost ¶
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 ¶
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 ¶
ListReportsByCustomID implements same signature of the DB interface.
func (*MemDB) ListSSHServers ¶
ListSSHServers implements same signature of the DB interface.
func (*MemDB) PutSSHServer ¶
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 ¶
ValidateAPIKey implements same signature of the DB interface.
type MongoDB ¶
type MongoDB struct {
// contains filtered or unexported fields
}
MongoDB implements DB interface.
func NewMongoDB ¶
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 ¶
CountReports counts number of records in node table.
func (*MongoDB) DeleteReport ¶ added in v0.1.1
DeleteReport implements same signature of the DB interface.
func (*MongoDB) DeleteUserSession ¶ added in v0.1.0
DeleteUserSession implements same signature of the DB interface.
func (*MongoDB) GetReportByID ¶
GetReportByID implements same signature of the DB interface.
func (*MongoDB) GetSSHServerByHost ¶
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 ¶
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 ¶
ListSSHServers implements same signature of the DB interface.
func (*MongoDB) PutSSHServer ¶
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 ¶
ValidateAPIKey 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
SubReports generates subsets of source reports.
func (Report) DiskUsageAsPercentage ¶
DiskUsageAsPercentage calculates disk usage as percentage.
func (Report) DownloadMBPS ¶
DownloadMBPS formats download throughput as Mbps.
func (Report) IsBootTimeReport ¶
IsBootTimeReport checks report triggered by boot time or not.
func (Report) IsIntervalReport ¶
IsIntervalReport checks report triggered by interval timer or not.
func (Report) IsSSHConnectedReport ¶
IsSSHConnectedReport checks report triggered by ssh connected or not.
func (Report) UploadMBPS ¶
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.
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) 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.