zoneminder

package module
v0.0.0-...-8962b97 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2017 License: Apache-2.0 Imports: 11 Imported by: 0

README

GoZone

Zoneminder is a great surveilance system for DIY setups and Golang is great for small services within DIY setups. So it just makes sense to bring them together.

Install

go get github.com/bah2830/GoZone

Monitors

Get All Monitors
import zm "github.com/bah2830/GoZone"

client, err := zm.NewClient("http://192.168.1.10/zm", "username", "password")
if err != nil {
    log.Fatal(err)
}

monitors, err := client.GetMonitors()
if err != nil {
    log.Fatal(err)
}

log.Printf("%+v", monitors)
Getting Events For A Monitor
import zm "github.com/bah2830/GoZone"

client, err := zm.NewClient("http://192.168.1.10/zm", "username", "password")
if err != nil {
    log.Fatal(err)
}

monitor, err := client.GetMonitorById(1)
if err != nil {
    log.Fatal(err)
}

events, err := monitor.GetEvents(nil)
if err != nil {
    log.Fatal(err)
}

log.Printf("%+v", events)
Monitoring For Events
import zm "github.com/bah2830/GoZone"

client, err := zm.NewClient("http://192.168.1.10/zm", "username", "password")
if err != nil {
    log.Fatal(err)
}

monitor, err := client.GetMonitorById(1)
if err != nil {
    log.Fatal(err)
}

eventChan := make(chan zoneminder.Events)
m.MonitorForEvents("Motion", 5, eventChan)

for {
    select {
    case e := <-eventChan:
        log.Printf("\n%+v", e)
    default:
        time.Sleep(30 * time.Second)
        m.StopEventMonitoring()
        return
    }
}

Events

Get All Events

This can return well over the default 100 pagination limit. Use filters to narrow that down.

import zm "github.com/bah2830/GoZone"

client, err := zm.NewClient("http://192.168.1.10/zm", "username", "password")
if err != nil {
    log.Fatal(err)
}

events, err := client.GetEvents(&zm.EventOpts{
    Cause: "Motion",
})

if err != nil {
    log.Fatal(err)
}

log.Printf("%+v", events)
Monitor For Events
import zm "github.com/bah2830/GoZone"

client, err := zm.NewClient("http://192.168.1.10/zm", "username", "password")
if err != nil {
    log.Fatal(err)
}

eventChan := make(chan zoneminder.Events)
c.MonitorForEvents(&zm.EventOpts{Cause: "Motion"}, 5, eventChan)

for {
    select {
    case e := <-eventChan:
        log.Printf("\n%+v", e)
    default:
        time.Sleep(30 * time.Second)
        c.StopEventMonitoring()
        return
    }
}

Documentation

Index

Constants

View Source
const Version = 0.7

Version of the package

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Host    string
	Cookies *cookiejar.Jar
	// contains filtered or unexported fields
}

Client is the api client used for communicating with the zoneminder API

func NewClient

func NewClient(host, username, password string) (*Client, error)

NewClient creates the remote client for api communication to zoneminder.

func (*Client) AddMonitor

func (c *Client) AddMonitor(opts MonitorOpts) (Monitor, error)

func (*Client) GetEventById

func (c *Client) GetEventById(ID int) (Event, error)

func (*Client) GetEvents

func (c *Client) GetEvents(opts *EventOpts) (Events, error)

func (*Client) GetMonitorById

func (c *Client) GetMonitorById(ID int) (Monitor, error)

func (*Client) GetMonitors

func (c *Client) GetMonitors() (Monitors, error)

func (*Client) MonitorForEvents

func (c *Client) MonitorForEvents(opts *EventOpts, interval int, eventChan chan Events)

func (*Client) StopEventMonitoring

func (c *Client) StopEventMonitoring()

type Collection

type Collection interface {
	GetByID(id int)
	GetByName(name string)
}

type Event

type Event struct {
	*Client
	ID          int `json:",string"`
	MonitorID   int `json:",string"`
	Name        string
	Cause       string
	StartTime   date
	EndTime     date
	Width       int     `json:",string"`
	Height      int     `json:",string"`
	Length      float64 `json:",string"`
	Frames      int     `json:",string"`
	AlarmFrames int     `json:",string"`
	TotScore    int     `json:",string"`
	AvgScore    int     `json:",string"`
	MaxScore    int     `json:",string"`
	Archived    int     `json:",string"`
	Videoed     int     `json:",string"`
	Uploaded    int     `json:",string"`
	Emailed     int     `json:",string"`
	Message     int     `json:",string"`
	Executed    int     `json:",string"`
	Notes       string
}

Event is an event sent back from zoneminder

func (Event) Refresh

func (e Event) Refresh() (Event, error)

type EventOpts

type EventOpts struct {
	MonitorID          int
	Cause              string
	StartTime          time.Time
	StartTimeOperation string
	EndTime            time.Time
	EndTimeOperation   string
}

type Events

type Events []Event

func (Events) GetByID

func (events Events) GetByID(id int) Event

func (Events) GetByMonitorID

func (events Events) GetByMonitorID(id int) Events

type Monitor

type Monitor struct {
	*Client
	ID                  int `json:",string"`
	Name                string
	ServerID            int `json:",string"`
	Type                string
	Function            string
	Enabled             int `json:",string"`
	LinkedMonitors      string
	Triggers            string
	Device              string
	Channel             int `json:",string"`
	Format              int `json:",string"`
	V4LMultiBuffer      bool
	V4LCapturesPerFrame int `json:",string"`
	Protocol            string
	Method              string
	Host                string
	Port                int `json:",string"`
	SubPath             string
	Path                string
	Options             string
	User                string
	Pass                string
	Width               int `json:",string"`
	Height              int `json:",string"`
	Colours             int `json:",string"`
	Palette             int `json:",string"`
	Orientation         int `json:",string"`
	Deinterlacing       int `json:",string"`
	RTSPDescribe        bool
	Brightness          int `json:",string"`
	Contrast            int `json:",string"`
	Hue                 int `json:",string"`
	Colour              int `json:",string"`
	EventPrefix         string
	LabelFormat         string
	LabelX              int     `json:",string"`
	LabelY              int     `json:",string"`
	LabelSize           int     `json:",string"`
	ImageBufferCount    int     `json:",string"`
	WarmupCount         int     `json:",string"`
	PreEventCount       int     `json:",string"`
	PostEventCount      int     `json:",string"`
	StreamReplayBuffer  int     `json:",string"`
	AlarmFrameCount     int     `json:",string"`
	SectionLength       int     `json:",string"`
	FrameSkip           int     `json:",string"`
	MotionFrameSkip     int     `json:",string"`
	AnalysisFPS         float64 `json:",string"`
	AnalysisUpdateDelay int     `json:",string"`
	MaxFPS              float64 `json:",string"`
	AlarmMaxFPS         float64 `json:",string"`
	FPSReportInterval   int     `json:",string"`
	RefBlendPerc        int     `json:",string"`
	AlarmRefBlendPerc   int     `json:",string"`
	Controllable        int     `json:",string"`
	ControlID           int     `json:",string"`
	ControlDevice       string
	ControlAddress      string
	AutoStopTimeout     string
	TrackMotion         int `json:",string"`
	TrackDelay          int `json:",string"`
	ReturnLocation      int `json:",string"`
	ReturnDelay         int `json:",string"`
	DefaultView         string
	DefaultRate         int `json:",string"`
	DefaultScale        int `json:",string"`
	SignalCheckColour   string
	WebColour           string
	Exif                bool
	Sequence            int `json:",string"`
	// contains filtered or unexported fields
}

Monitor is the monitor object from zoneminder

func (*Monitor) AlarmStatus

func (m *Monitor) AlarmStatus() (int, error)

func (*Monitor) Disable

func (m *Monitor) Disable() error

func (*Monitor) Edit

func (m *Monitor) Edit(opts MonitorOpts) error

func (*Monitor) Enable

func (m *Monitor) Enable() error

func (*Monitor) ForceAlarm

func (m *Monitor) ForceAlarm() error

func (*Monitor) GetEvents

func (m *Monitor) GetEvents(opts *EventOpts) (Events, error)

func (*Monitor) MonitorForEvents

func (m *Monitor) MonitorForEvents(eventType string, interval int, eventChan chan Events)

func (*Monitor) Refresh

func (m *Monitor) Refresh() (Monitor, error)

func (*Monitor) SetFunction

func (m *Monitor) SetFunction(f string) error

func (*Monitor) StopAlarm

func (m *Monitor) StopAlarm() error

func (*Monitor) StopEventMonitoring

func (m *Monitor) StopEventMonitoring()

type MonitorOpts

type MonitorOpts struct {
	Name     string
	Function string
	Protocol string
	Method   string
	Host     string
	Port     int
	Path     string
	Width    int
	Height   int
	Colours  int
}

type Monitors

type Monitors []Monitor

func (*Monitors) GetByID

func (m *Monitors) GetByID(id int) Monitor

func (*Monitors) GetByName

func (m *Monitors) GetByName(name string) Monitor

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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