datastore

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package datastore : データ保存

Package datastore : データ保存

Index

Constants

View Source
const (
	LogModeNone = iota
	LogModeAlways
	LogModeOnChange
	LogModeAI
)
View Source
const (
	DrawItemTypeRect = iota
	DrawItemTypeEllipse
	DrawItemTypeText
	DrawItemTypeImage
	DrawItemTypePollingText
	DrawItemTypePollingGauge
	DrawItemTypePollingNewGauge
	DrawItemTypePollingBar
	DrawItemTypePollingLine
)

Variables

View Source
var (

	// Conf Data on Memory
	MapConf      MapConfEnt
	BackImage    BackImageEnt
	NotifyConf   NotifyConfEnt
	DiscoverConf DiscoverConfEnt
	AIConf       AIConfEnt
	LocConf      LocConfEnt
	AutoCharCode bool
	// Restart snmptrapd
	RestartSnmpTrapd bool

	//
	MIBDB *gomibdb.MIBDB

	Dark bool
)
View Source
var (
	ErrNoPayload     = fmt.Errorf("no payload")
	ErrInvalidNode   = fmt.Errorf("invalid node")
	ErrInvalidParams = fmt.Errorf("invald params")
	ErrDBNotOpen     = fmt.Errorf("db not open")
	ErrInvalidID     = fmt.Errorf("invalid id")
)

Define errors

View Source
var MIBInfoMap = make(map[string]*MIBInfo)
View Source
var MIBModules = []*MIBModuleEnt{}
View Source
var MIBTree = []*MIBTreeEnt{}
View Source
var MIBTypeMap = make(map[string]MIBTypeEnt)
View Source
var PollingTemplateList []*PollingTemplateEnt

Functions

func AddDrawItem

func AddDrawItem(di *DrawItemEnt) error

func AddEventLog

func AddEventLog(e *EventLogEnt)

func AddLine

func AddLine(l *LineEnt) error

func AddNode

func AddNode(n *NodeEnt) error

func AddOrUpdateIcon

func AddOrUpdateIcon(i *IconEnt) error

func AddPolling

func AddPolling(p *PollingEnt) error

AddPolling : ポーリングを追加する

func AddPollingLog

func AddPollingLog(p *PollingEnt) error

func BackupDB

func BackupDB(file string) error

func ClearPollingLog

func ClearPollingLog(pollingID string) error

ClearPollingLog : ポーリングログを削除する

func CloseDB

func CloseDB()

CloseDB : DBをクローズする

func DeleteAIResult

func DeleteAIResult(id string) error

func DeleteAllLogs

func DeleteAllLogs(b string) error

func DeleteArpEnt added in v0.9.1

func DeleteArpEnt(ips []string) error

DeleteArpEntは、指定のIPアドレスに関連したARPテーブルとARPログを削除する

func DeleteDrawItem

func DeleteDrawItem(id string) error

func DeleteGeoIP

func DeleteGeoIP()

DeleteGeoIP : GeoIP DBを削除する

func DeleteIcon

func DeleteIcon(icon string) error

func DeleteLine

func DeleteLine(lineID string) error

func DeleteNode

func DeleteNode(nodeID string) error

func DeleteNodeStateChanged

func DeleteNodeStateChanged(id string)

func DeletePollings

func DeletePollings(ids []string) error

func DelteImage

func DelteImage(path string) error

func FindVendor

func FindVendor(mac string) string

FindVendor : Find Vendor Name from MAC Address

func ForEachArp

func ForEachArp(f func(*ArpEnt) bool) error

func ForEachEventLog

func ForEachEventLog(st, et int64, f func(*EventLogEnt) bool) error

func ForEachItems

func ForEachItems(f func(*DrawItemEnt) bool)

func ForEachLastArpLogs

func ForEachLastArpLogs(f func(*ArpLogEnt) bool) error

ForEachLastArpLogs は最新のARP Logを返します。

func ForEachLastEventLog

func ForEachLastEventLog(f func(*EventLogEnt) bool) error

func ForEachLastPollingLog

func ForEachLastPollingLog(pollingID string, f func(*PollingLogEnt) bool) error

func ForEachLastSyslog

func ForEachLastSyslog(f func(*SyslogEnt) bool) error

ForEachLastSyslog get syslogs

func ForEachLastTraps

func ForEachLastTraps(f func(*TrapEnt) bool) error

ForEachLastTraps get TRAP

func ForEachLines

func ForEachLines(f func(*LineEnt) bool)

ForEachLines : Line毎の処理

func ForEachLogs added in v1.4.0

func ForEachLogs(st, et int64, lt string, f func(*LogEnt) bool) error

ForEachLogsは指定した条件のログを返します。

func ForEachNodes

func ForEachNodes(f func(*NodeEnt) bool)

func ForEachPollings

func ForEachPollings(f func(*PollingEnt) bool)

ForEachPollings : ポーリング毎の処理

func ForEachStateChangedNodes

func ForEachStateChangedNodes(f func(string) bool)

func ForEachSyslog added in v1.3.0

func ForEachSyslog(st, et int64, f func(*SyslogEnt) bool) error

ForEachSyslog get syslogs

func ForEachTraps added in v1.3.0

func ForEachTraps(st, et int64, f func(*TrapEnt) bool) error

ForEachTraps get TRAP

func GenSSHPrivateKey added in v1.4.0

func GenSSHPrivateKey() []byte

func GetDBSize

func GetDBSize() int64

func GetDataStorePath

func GetDataStorePath() string

Data Storeのパスを返す、何かと必要なので

func GetImage

func GetImage(path string) ([]byte, error)

func GetImageList

func GetImageList() []string

func GetLoc

func GetLoc(sip string) string

func GetPrivateKey

func GetPrivateKey(pm bool) []byte

func GetSSHPublicKey added in v1.4.0

func GetSSHPublicKey() (string, error)

func GetServiceName

func GetServiceName(prot, port int) (string, bool)

func GetSshdPublicKeys added in v1.4.0

func GetSshdPublicKeys() string

func Init

func Init(ctx context.Context, path string, wg *sync.WaitGroup) error

func IsGlobalUnicast

func IsGlobalUnicast(ips string) bool

func IsPrivateIP

func IsPrivateIP(ip net.IP) bool

func LoadMailTemplate

func LoadMailTemplate(t string) string

func PrintDateAndTime added in v1.2.0

func PrintDateAndTime(i interface{}) string

DISPLAY-HINT "2d-1d-1d,1d:1d:1d.1d,1a1d:1d"

func PrintHintedMIBIntVal added in v1.1.0

func PrintHintedMIBIntVal(val int32, hint string, us bool) string

func PrintIPAddress added in v1.2.0

func PrintIPAddress(i interface{}) string

func PrintMIBStringVal added in v1.2.0

func PrintMIBStringVal(i interface{}) string

func ResetArpTable

func ResetArpTable() error

ResetArpTableは、ARPテーブルとARPログをクリアする

func SaveAIConf

func SaveAIConf() error

func SaveAIResult

func SaveAIResult(res *AIResult) error

func SaveBackImage

func SaveBackImage() error

func SaveDiscoverConf

func SaveDiscoverConf() error

func SaveImage

func SaveImage(path string, img []byte) error

func SaveLocConf added in v1.1.0

func SaveLocConf() error

func SaveLogBuffer

func SaveLogBuffer(logBuffer []*LogEnt)

func SaveMapConf

func SaveMapConf() error

func SaveMapData

func SaveMapData()

SaveMapData: 24時間毎にマップのデータをDBへ保存する

func SaveNotifyConf

func SaveNotifyConf() error

func SaveSshdPublicKeys added in v1.4.0

func SaveSshdPublicKeys(pk string) error

func SetDark

func SetDark(dark bool) error

func SetNodeStateChanged

func SetNodeStateChanged(id string)

SetNodeStateChanged :

func UpdateArpEnt

func UpdateArpEnt(ip, mac string) error

func UpdateGeoIP

func UpdateGeoIP(path string) error

UpdateGeoIP : GeoIP DBを更新する

func UpdateLine

func UpdateLine(l *LineEnt) error

func UpdatePolling

func UpdatePolling(p *PollingEnt, save bool) error

Types

type AIConfEnt

type AIConfEnt struct {
	HighThreshold float64 `json:"HighThreshold"`
	LowThreshold  float64 `json:"LowThreshold"`
	WarnThreshold float64 `json:"WarnThreshold"`
}

type AIResult

type AIResult struct {
	PollingID string      `json:"PollingID"`
	LastTime  int64       `json:"LastTime"`
	ScoreData [][]float64 `json:"ScoreData"`
}

func GetAIReesult

func GetAIReesult(id string) (*AIResult, error)

type ArpEnt

type ArpEnt struct {
	IP     string `json:"IP"`
	MAC    string `json:"MAC"`
	NodeID string `json:"NodeID"`
	Vendor string `json:"Vendor"`
}

type ArpLogEnt

type ArpLogEnt struct {
	Time   int64  `json:"Time"`
	State  string `json:"State"`
	IP     string `json:"IP"`
	NewMAC string `json:"NewMAC"`
	OldMAC string `json:"OldMAC"`
}

type BackImageEnt

type BackImageEnt struct {
	X      int    `json:"X"`
	Y      int    `json:"Y"`
	Width  int    `json:"Width"`
	Height int    `json:"Height"`
	Path   string `json:"Path"`
}

type DiscoverConfEnt

type DiscoverConfEnt struct {
	StartIP    string `json:"StartIP"`
	EndIP      string `json:"EndIP"`
	Timeout    int    `json:"Timeout"`
	Retry      int    `json:"Retry"`
	X          int    `json:"X"`
	Y          int    `json:"Y"`
	AddPolling bool   `json:"AddPolling"`
	PortScan   bool   `json:"PortScan"`
}

type DrawItemEnt

type DrawItemEnt struct {
	ID        string       `json:"ID"`
	Type      DrawItemType `json:"Type"`
	X         int          `json:"X"`
	Y         int          `json:"Y"`
	W         int          `json:"W"`
	H         int          `json:"H"`
	Color     string       `json:"Color"`
	Path      string       `json:"Path"`
	Text      string       `json:"Text"`
	Size      int          `json:"Size"`
	PollingID string       `json:"PollingID"`
	VarName   string       `json:"VarName"`
	Format    string       `json:"Format"`
	Value     float64      `json:"Value"`
	Scale     float64      `json:"Scale"`
	Cond      int          `json:"Cond"`
	Values    []float64    `json:"Values"`
}

func GetDrawItem

func GetDrawItem(id string) *DrawItemEnt

type DrawItemType

type DrawItemType int

type EventLogEnt

type EventLogEnt struct {
	Time      int64  `json:"Time"`
	Type      string `json:"Type"`
	Level     string `json:"Level"`
	NodeName  string `json:"NodeName"`
	NodeID    string `json:"NodeID"`
	Event     string `json:"Event"`
	LastLevel string `json:"LastLevel"`
}

type IconEnt

type IconEnt struct {
	Name string `json:"Name"`
	Icon string `json:"Icon"`
	Code int64  `json:"Code"`
}

func GetIcons

func GetIcons() []*IconEnt

type LineEnt

type LineEnt struct {
	ID         string `json:"ID"`
	NodeID1    string `json:"NodeID1"`
	PollingID1 string `json:"PollingID1"`
	State1     string `json:"State1"`
	NodeID2    string `json:"NodeID2"`
	PollingID2 string `json:"PollingID2"`
	State2     string `json:"State2"`
	PollingID  string `json:"PollingID"`
	Width      int    `json:"Width"`
	State      string `json:"State"`
	Info       string `json:"Info"`
	Port       string `json:"Port"`
}

func GetLine

func GetLine(lineID string) *LineEnt

type LocConfEnt added in v1.1.0

type LocConfEnt struct {
	Style    string  `json:"Style"`
	Center   string  `json:"Center"`
	Zoom     float64 `json:"Zoom"`
	IconSize int     `json:"IconSize"`
}

LocConfEnt : 地図設定

type LogEnt

type LogEnt struct {
	Time int64 // UnixNano()
	Type string
	Log  string
}

type LogFilterEnt

type LogFilterEnt struct {
	StartTime string
	EndTime   string
	Filter    string
	LogType   string
}

type MIBInfo

type MIBInfo struct {
	OID         string
	Status      string
	Type        string
	Enum        string
	Defval      string
	Units       string
	Index       string
	Description string
	EnumMap     map[int]string
	Hint        string
}

func FindMIBInfo

func FindMIBInfo(name string) *MIBInfo

type MIBModuleEnt

type MIBModuleEnt struct {
	Type  string `json:"Type"`
	File  string `json:"File"`
	Name  string `json:"Name"`
	Error string `json:"Error"`
}

読み込んだMIBのリスト

type MIBTreeEnt

type MIBTreeEnt struct {
	OID      string `json:"oid"`
	Name     string `json:"name"`
	MIBInfo  *MIBInfo
	Children []*MIBTreeEnt `json:"children"`
}

type MIBTypeEnt added in v1.1.0

type MIBTypeEnt struct {
	Enum    string
	EnumMap map[int]string
	Hint    string
}

type MapConfEnt

type MapConfEnt struct {
	MapName        string `json:"MapName"`
	PollInt        int    `json:"PollInt"`
	Timeout        int    `json:"Timeout"`
	Retry          int    `json:"Retry"`
	LogDays        int    `json:"LogDays"`
	SnmpMode       string `json:"SnmpMode"`
	Community      string `json:"Community"`
	SnmpUser       string `json:"SnmpUser"`
	SnmpPassword   string `json:"SnmpPassword"`
	EnableSyslogd  bool   `json:"EnableSyslogd"`
	EnableTrapd    bool   `json:"EnableTrapd"`
	EnableArpWatch bool   `json:"EnableArpWatch"`
	EnableSshd     bool   `json:"EnableSshd"`
	IconSize       int    `json:"IconSize"`
}

MapConfEnt : マップ設定

type NodeEnt

type NodeEnt struct {
	ID        string `json:"ID"`
	Name      string `json:"Name"`
	Descr     string `json:"Descr"`
	Icon      string `json:"Icon"`
	State     string `json:"State"`
	X         int    `json:"X"`
	Y         int    `json:"Y"`
	IP        string `json:"IP"`
	MAC       string `json:"MAC"`
	Vendor    string `json:"Vendor"`
	SnmpMode  string `json:"SnmpMode"`
	Community string `json:"Community"`
	User      string `json:"User"`
	SSHUser   string `json:"SSHUser"`
	Password  string `json:"Password"`
	PublicKey string `json:"PublicKey"`
	URL       string `json:"URL"`
	AddrMode  string `json:"AddrMode"`
	AutoAck   bool   `json:"AutoAck"`
	Loc       string `json:"Loc"`
}

func FindNodeFromIP

func FindNodeFromIP(ip string) *NodeEnt

func FindNodeFromMAC

func FindNodeFromMAC(mac string) *NodeEnt

func FindNodeFromName

func FindNodeFromName(name string) *NodeEnt

func GetNode

func GetNode(nodeID string) *NodeEnt

type NotifyConfEnt

type NotifyConfEnt struct {
	MailServer         string `json:"MailServer"`
	InsecureSkipVerify bool   `json:"InsecureSkipVerify"`
	User               string `json:"User"`
	Password           string `json:"Password"`
	MailTo             string `json:"MailTo"`
	MailFrom           string `json:"MailFrom"`
	Subject            string `json:"Subject"`
	Interval           int    `json:"Interval"`
	Level              string `json:"Level"`
	Report             bool   `json:"Report"`
	NotifyRepair       bool   `json:"NotifyRepair"`
	ExecCmd            string `json:"ExecCmd"`
	BeepHigh           string `json:"BeepHigh"`
	BeepLow            string `json:"BeepLow"`
	LineNotifyRepair   bool   `json:"LineNotifyRepair"`
	LineLevel          string `json:"LineLevel"`
	LineToken          string `json:"LineToken"`
}

type PollingEnt

type PollingEnt struct {
	ID           string                 `json:"ID"`
	Name         string                 `json:"Name"`
	NodeID       string                 `json:"NodeID"`
	Type         string                 `json:"Type"`
	Mode         string                 `json:"Mode"`
	Params       string                 `json:"Params"`
	Filter       string                 `json:"Filter"`
	Extractor    string                 `json:"Extractor"`
	Script       string                 `json:"Script"`
	Level        string                 `json:"Level"`
	PollInt      int                    `json:"PollInt"`
	Timeout      int                    `json:"Timeout"`
	Retry        int                    `json:"Retry"`
	LogMode      int                    `json:"LogMode"`
	NextTime     int64                  `json:"NextTime"`
	LastTime     int64                  `json:"LastTime"`
	Result       map[string]interface{} `json:"Result"`
	State        string                 `json:"State"`
	FailAction   string                 `json:"FailAction"`
	RepairAction string                 `json:"RepairAction"`
}

func GetPolling

func GetPolling(id string) *PollingEnt

GetPolling : ポーリングを取得する

type PollingLogEnt

type PollingLogEnt struct {
	Time      int64                  `json:"Time"`
	PollingID string                 `json:"PollingID"`
	State     string                 `json:"State"`
	Result    map[string]interface{} `json:"Result"`
}

func GetAllPollingLog

func GetAllPollingLog(pollingID string) []*PollingLogEnt

GetAllPollingLog :全てのポーリングログを取得する

type PollingTemplateEnt

type PollingTemplateEnt struct {
	ID        int    `json:"ID"`
	Name      string `json:"Name"`
	Level     string `json:"Level"`
	Type      string `json:"Type"`
	Mode      string `json:"Mode"`
	Params    string `json:"Params"`
	Filter    string `json:"Filter"`
	Extractor string `json:"Extractor"`
	Script    string `json:"Script"`
	Descr     string `json:"Descr"`
	AutoParam string `json:"AutoParam"`
}

func GetPollingTemplate

func GetPollingTemplate(id int) *PollingTemplateEnt

type SyslogEnt

type SyslogEnt struct {
	Time     int64  `json:"Time"`
	Level    string `json:"Level"`
	Host     string `json:"Host"`
	Type     string `json:"Type"`
	Tag      string `json:"Tag"`
	Message  string `json:"Message"`
	Severity int    `json:"Severity"`
	Facility int    `json:"Facility"`
}

for syslog

type TrapEnt

type TrapEnt struct {
	Time        int64  `json:"Time"`
	FromAddress string `json:"FromAddress"`
	TrapType    string `json:"TrapType"`
	Variables   string `json:"Variables"`
}

Jump to

Keyboard shortcuts

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