database

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2017 License: MIT Imports: 11 Imported by: 6

Documentation

Overview

Package database acts as storage backend for amtgo's webserver.

Index

Constants

View Source
const (
	// NotificationTypeUser maps to user symbol
	NotificationTypeUser = "user"
	// NotificationTypePowerOff maps to power-off symbol
	NotificationTypePowerOff = "toggle-off"
	// NotificationTypePowerOn maps to power-on symbol
	NotificationTypePowerOn = "toggle-on"
	// NotificationTypeWarning maps to warning symbol
	NotificationTypeWarning = "warning"
	// NotificationTypeComment maps to comment bubble symbol
	NotificationTypeComment = "comment"
)

Variables

View Source
var (
	// DbDriver selects driver to use: sqlite3 | mysql
	DbDriver string
	// DbFile points a SQLite database file
	DbFile string
	// DbUser etc. below are MySQL only
	DbUser string
	// DbPassword for MySQL
	DbPassword string
	// DbName for MySQL
	DbName string
	// DbHost for MySQL
	DbHost string
	// DbPort for MySQL
	DbPort string
)

Functions

func CloseDB

func CloseDB()

CloseDB closes SQLite database

func DeleteHost

func DeleteHost(id int) (string, bool)

DeleteHost deletes a single host

func DeleteJob

func DeleteJob(id int) (string, bool)

DeleteJob deletes a single job

func DeleteOptionset

func DeleteOptionset(id int) (string, bool)

DeleteOptionset deletes a single host

func DeleteOu

func DeleteOu(id int) (string, bool)

DeleteOu deletes a single host

func DeleteUser

func DeleteUser(id int) (string, bool)

DeleteUser deletes a single user

func GetHostJSON

func GetHostJSON(id int) string

GetHostJSON gets a single host

func GetHostNamesByID

func GetHostNamesByID(ids []string) (hostnames []string)

GetHostNamesByID gets hostnames for hosts with given IDs

func GetHostsJSON

func GetHostsJSON() string

GetHostsJSON gets all hosts

func GetJobJSON

func GetJobJSON(id int) string

GetJobJSON gets a single job

func GetJobsJSON

func GetJobsJSON() string

GetJobsJSON gets all jobs

func GetLaststateJSON

func GetLaststateJSON(id int) string

GetLaststateJSON get laststate entry -- UNUSED

func GetLogdaysJSON

func GetLogdaysJSON() string

GetLogdaysJSON gets all Logdays

func GetNotificationJSON

func GetNotificationJSON(id int) string

GetNotificationJSON gets a single notification

func GetNotificationsJSON

func GetNotificationsJSON() string

GetNotificationsJSON gets all notifications

func GetOptionset

func GetOptionset(id int) (o amt.Optionset)

GetOptionset gets a single optionset

func GetOptionsetJSON

func GetOptionsetJSON(id int) string

GetOptionsetJSON gets a single optionset

func GetOptionsets

func GetOptionsets() (optionsets []amt.Optionset)

GetOptionsets gets all optionsets

func GetOptionsetsJSON

func GetOptionsetsJSON() string

GetOptionsetsJSON gets optionsets

func GetOuJSON

func GetOuJSON(id int) string

GetOuJSON gets a single OU

func GetOusJSON

func GetOusJSON() string

GetOusJSON gets all OUs

func GetStatelogsJSON

func GetStatelogsJSON(ouid int, unixtime int) []byte

GetStatelogsJSON gets all statelogs for one ou at specific day

func GetUserJSON

func GetUserJSON(id int) string

GetUserJSON gets a single user

func GetUsersJSON

func GetUsersJSON() string

GetUsersJSON gets all users

func InitDB

func InitDB()

InitDB initializes DB based on driver

func InitDBMysql

func InitDBMysql()

InitDBMysql initializes DB schema

func InitDBSQlite

func InitDBSQlite()

InitDBSQlite initializes DB schema

func InsertHost

func InsertHost(body io.ReadCloser) string

InsertHost inserts a single host to DB

func InsertJob

func InsertJob(j Job) string

InsertJob inserts a (scheduled) job record

func InsertNotification

func InsertNotification(ntype string, message string)

InsertNotification inserts a user record

func InsertOptionset

func InsertOptionset(body io.ReadCloser) string

InsertOptionset creates an Optionset

func InsertOu

func InsertOu(body io.ReadCloser) string

InsertOu creates a single org unit

func InsertStatelog

func InsertStatelog(hostid int, http int, amt int, port int)

InsertStatelog adds a record in statelog table

func InsertUser

func InsertUser(u User)

InsertUser inserts a user record

func OpenDB

func OpenDB()

OpenDB opens DB connection based on driver

func OpenDBMySQL

func OpenDBMySQL()

OpenDBMySQL opens MySQL database

func OpenDBSQlite

func OpenDBSQlite()

OpenDBSQlite opens SQLite database

func UpdateJob

func UpdateJob(j Job) string

UpdateJob updates a (scheduled) job record

func UpdateOptionset

func UpdateOptionset(id int, body io.ReadCloser) string

UpdateOptionset updates an Optionset

func UpdateOu

func UpdateOu(id int, body io.ReadCloser) string

UpdateOu updates a OU record

Types

type Host

type Host struct {
	ID       int    `json:"id"`
	OuID     int    `json:"ou_id" db:"ou_id"`
	Hostname string `json:"hostname"`
	Enabled  int    `json:"enabled"`
}

Host is a AMT enabled client to be controlled.

func GetHosts

func GetHosts() (hosts []Host)

GetHosts gets all hosts

func GetHostsByOu

func GetHostsByOu(ou int) (hosts []Host)

GetHostsByOu gets all hosts of a OU.

type Hosts

type Hosts struct {
	Hosts []Host `json:"hosts"`
}

Hosts array for ember

type Job

type Job struct {
	ID             int      `json:"id"`
	JobType        int      `json:"job_type" db:"job_type"`
	JobStatus      int      `json:"job_status" db:"job_status"`
	UserID         int      `json:"user_id" db:"user_id"`
	AmtcCmd        *string  `json:"amtc_cmd" db:"amtc_cmd"`
	AmtcDelay      *float64 `json:"amtc_delay" db:"amtc_delay"`
	AmtcBootdevice *string  `json:"amtc_bootdevice" db:"amtc_bootdevice"`
	AmtcHosts      *string  `json:"amtc_hosts" db:"amtc_hosts"`
	OuID           *int     `json:"ou_id" db:"ou_id"`
	StartTime      int      `json:"start_time" db:"start_time"`
	RepeatInterval *int     `json:"repeat_interval" db:"repeat_interval"`
	RepeatDays     *int     `json:"repeat_days" db:"repeat_days"`
	LastStarted    *int     `json:"last_started" db:"last_started"`
	LastDone       *int     `json:"last_done" db:"last_done"`
	ProcPid        *int     `json:"proc_pid" db:"proc_pid"`
	Description    *string  `json:"description"`
}

Job is a scheduled job

func GetScheduledJobs

func GetScheduledJobs(weekDay int, minuteOfDay int) (myjobs []Job)

GetScheduledJobs gets all scheduled jobs for a given weekday and minute of day.

type Jobs

type Jobs struct {
	Jobs []Job `json:"jobs"`
}

Jobs for ember

type Notification

type Notification struct {
	ID      int    `json:"id"`
	Tstamp  int    `json:"tstamp"`
	UserID  int    `json:"user_id" db:"user_id"`
	Ntype   string `json:"ntype"`
	Message string `json:"message"`
}

Notification is a GUI notification (e.g. job started, completed...)

type Notifications

type Notifications struct {
	Notifications []Notification `json:"notifications"`
}

Notifications array for ember

type Ou

type Ou struct {
	ID          int     `json:"id"`
	ParentID    *int    `json:"parent_id" db:"parent_id"`
	OptionsetID *int    `json:"optionset_id" db:"optionset_id"`
	Name        string  `json:"name"`
	Description string  `json:"description"`
	IdlePower   float32 `json:"idle_power" db:"idle_power"`
	Logging     int     `json:"logging"`
}

Ou describes an organizational unit (e.g. room)

func GetOu

func GetOu(id int) (o Ou)

GetOu gets a single OU.

func GetOus

func GetOus() (ous []Ou)

GetOus gets all OUs

type Ous

type Ous struct {
	Ous []Ou `json:"ous"`
}

Ous list multiple OUs for ember

type Statelog

type Statelog struct {
	HostID     int `json:"host_id" db:"host_id"`
	StateBegin int `json:"state_begin" db:"state_begin"`
	OpenPort   int `json:"open_port" db:"open_port"`
	StateAMT   int `json:"state_amt" db:"state_amt"`
	StateHTTP  int `json:"state_http" db:"state_http"`
}

Statelog -- unused?

type Statelogs

type Statelogs struct {
	Statelogs []Statelog `json:"statelogs"`
}

Statelogs wraps statelogs for json/emberjs

type User

type User struct {
	ID         int    `json:"id"`
	OuID       int    `json:"ou_id" db:"ou_id"`
	IsEnabled  int    `json:"is_enabled" db:"is_enabled"`
	IsAdmin    int    `json:"is_admin" db:"is_admin"`
	CanControl int    `json:"can_control" db:"can_control"`
	Name       string `json:"name"`
	Fullname   string `json:"fullname"`
	Password   string `json:"-"`
	Passsalt   string `json:"-"`
}

User represents a GUI user

func GetUser

func GetUser(name string) (u User)

GetUser gets a single user

func GetUsers

func GetUsers() (users []User)

GetUsers gets all Users

type Users

type Users struct {
	Users []User `json:"users"`
}

Users array for ember

Jump to

Keyboard shortcuts

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