-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9314b6b
Showing
13 changed files
with
1,613 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
# Go releaser | ||
dist/ | ||
|
||
/unifi-notifications | ||
|
||
*.xml | ||
|
||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
builds: | ||
- env: | ||
- CGO_ENABLED=0 | ||
archives: | ||
- replacements: | ||
darwin: Darwin | ||
linux: Linux | ||
windows: Windows | ||
386: i386 | ||
amd64: x86_64 | ||
checksum: | ||
name_template: 'checksums.txt' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# ---- Build container | ||
FROM golang:alpine AS builder | ||
WORKDIR /unifi-notifications | ||
COPY . . | ||
RUN apk add --no-cache git | ||
RUN go build -v ./... | ||
|
||
# ---- App container | ||
FROM alpine:latest as unifi-notifications | ||
ENV NOTIFCATION_SERVICES=slack | ||
ENV UNIFI_URL= | ||
ENV UNIFI_SITES= | ||
ENV UNIFI_USERNAME= | ||
ENV UNIFI_PASSWORD= | ||
ENV SLACK_ALARMS_WEBHOOK= | ||
ENV SLACK_EVENTS_WEBHOOK= | ||
RUN apk --no-cache add ca-certificates | ||
COPY --from=builder unifi-notifications/unifi-notifications / | ||
ENTRYPOINT ./unifi-notifications | ||
LABEL Name=unifi-notifications Version=0.0.1 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# unifi-notifications | ||
Send events and alerts from Unify to a notification service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package model | ||
|
||
import ( | ||
"errors" | ||
"strings" | ||
|
||
"github.com/caarlos0/env" | ||
) | ||
|
||
type AppConfig struct { | ||
CheckInterval int `env:"CHECK_INTERVAL" envDefault:"1"` | ||
NotificationServices []string `env:"NOTIFCATION_SERVICES,required" envSeparator:","` | ||
} | ||
|
||
type LoggerConfig struct { | ||
Level string `env:"LOG_LEVEL" envDefault:"info"` | ||
} | ||
|
||
type UnifiConfig struct { | ||
URL string `env:"UNIFI_URL,required"` | ||
Sites []string `env:"UNIFI_SITES,required" envSeparator:","` | ||
Username string `env:"UNIFI_USERNAME,required"` | ||
Password string `env:"UNIFI_PASSWORD,required"` | ||
} | ||
|
||
type SlackConfig struct { | ||
AlarmsWebhook string `env:"SLACK_ALARMS_WEBHOOK,required"` | ||
EventsWebhook string `env:"SLACK_EVENTS_WEBHOOK,required"` | ||
} | ||
|
||
func NewConfig() (AppConfig, LoggerConfig, UnifiConfig, SlackConfig, error) { | ||
appConfig := AppConfig{} | ||
loggerConfig := LoggerConfig{} | ||
unifiConfig := UnifiConfig{} | ||
slackConfig := SlackConfig{} | ||
var errs []string | ||
for _, e := range []error{ | ||
env.Parse(&appConfig), | ||
env.Parse(&loggerConfig), | ||
env.Parse(&unifiConfig), | ||
} { | ||
if e != nil { | ||
errs = append(errs, e.Error()) | ||
} | ||
} | ||
|
||
for _, notificationService := range appConfig.NotificationServices { | ||
if notificationService == "slack" { | ||
err := env.Parse(&slackConfig) | ||
if err != nil { | ||
errs = append(errs, err.Error()) | ||
} | ||
} | ||
} | ||
|
||
var err error | ||
if len(errs) > 0 { | ||
err = errors.New(strings.Join(errs, ", ")) | ||
} | ||
return appConfig, loggerConfig, unifiConfig, slackConfig, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
package model | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
type UnifiLogin struct { | ||
Username string `json:"username"` | ||
Password string `json:"password"` | ||
} | ||
|
||
type UnifiSession struct { | ||
Key string | ||
Expiration time.Time | ||
} | ||
|
||
type UnifiPagination struct { | ||
Limit int `json:"_limit"` | ||
Start int `json:"_start"` | ||
} | ||
|
||
type UnifiSiteAlarms map[string]UnifiAlarms | ||
|
||
type UnifiSiteEvents map[string]UnifiEvents | ||
|
||
type Meta struct { | ||
RC string `json:"rc"` | ||
Count int64 `json:"count"` | ||
Msg string `json:"msg"` | ||
} | ||
|
||
type UnifiAlarms struct { | ||
Meta Meta `json:"meta"` | ||
Alarms []UnifiAlarm `json:"data"` | ||
} | ||
|
||
type UnifiAlarm struct { | ||
ID string `json:"_id"` | ||
Archived bool `json:"archived"` | ||
Timestamp int64 `json:"timestamp"` | ||
FlowID int64 `json:"flow_id"` | ||
InIface string `json:"in_iface"` | ||
EventType string `json:"event_type"` | ||
SrcIP string `json:"src_ip"` | ||
SrcMAC string `json:"src_mac"` | ||
SrcPort int64 `json:"src_port"` | ||
DestIP string `json:"dest_ip"` | ||
DstMAC string `json:"dst_mac"` | ||
DestPort int64 `json:"dest_port"` | ||
Proto string `json:"proto"` | ||
TxID int64 `json:"tx_id"` | ||
AppProto string `json:"app_proto"` | ||
Host string `json:"host"` | ||
Usgip string `json:"usgip"` | ||
UniqueAlertid string `json:"unique_alertid"` | ||
UsgipCountry string `json:"usgipCountry"` | ||
SrcipASN string `json:"srcipASN"` | ||
DstipASN string `json:"dstipASN"` | ||
UsgipASN string `json:"usgipASN"` | ||
Catname string `json:"catname"` | ||
InnerAlertAction string `json:"inner_alert_action"` | ||
InnerAlertGid int64 `json:"inner_alert_gid"` | ||
InnerAlertSignatureID int64 `json:"inner_alert_signature_id"` | ||
InnerAlertRev int64 `json:"inner_alert_rev"` | ||
InnerAlertSignature string `json:"inner_alert_signature"` | ||
InnerAlertCategory string `json:"inner_alert_category"` | ||
InnerAlertSeverity int64 `json:"inner_alert_severity"` | ||
Key string `json:"key"` | ||
Subsystem string `json:"subsystem"` | ||
SiteID string `json:"site_id"` | ||
Time int64 `json:"time"` | ||
Datetime time.Time `json:"datetime"` | ||
Msg string `json:"msg"` | ||
Ap string `json:"ap"` | ||
ApName string `json:"ap_name"` | ||
HandledAdminID string `json:"handled_admin_id"` | ||
HandledTime string `json:"handled_time"` | ||
Gw string `json:"gw"` | ||
GwName string `json:"gw_name"` | ||
VLAN int64 `json:"vlan"` | ||
ICMPType int64 `json:"icmp_type"` | ||
ICMPCode int64 `json:"icmp_code"` | ||
} | ||
|
||
type UnifiEvents struct { | ||
Meta Meta `json:"meta"` | ||
Events []UnifiEvent `json:"data"` | ||
} | ||
|
||
type UnifiEvent struct { | ||
ID string `json:"_id"` | ||
IP string `json:"ip"` | ||
Admin string `json:"admin"` | ||
SiteID string `json:"site_id"` | ||
IsAdmin bool `json:"is_admin"` | ||
Key string `json:"key"` | ||
Subsystem string `json:"subsystem"` | ||
Time int64 `json:"time"` | ||
Datetime time.Time `json:"datetime"` | ||
Msg string `json:"msg"` | ||
User string `json:"user"` | ||
Network string `json:"network"` | ||
Duration int64 `json:"duration"` | ||
Bytes int64 `json:"bytes"` | ||
SSID string `json:"ssid"` | ||
Ap string `json:"ap"` | ||
Radio string `json:"radio"` | ||
Channel string `json:"channel"` | ||
Hostname string `json:"hostname"` | ||
RadioFrom string `json:"radio_from"` | ||
RadioTo string `json:"radio_to"` | ||
Gw string `json:"gw"` | ||
GwName string `json:"gw_name"` | ||
ApName string `json:"ap_name"` | ||
Timestamp int64 `json:"timestamp"` | ||
FlowID int64 `json:"flow_id"` | ||
InIface string `json:"in_iface"` | ||
EventType string `json:"event_type"` | ||
SrcIP string `json:"src_ip"` | ||
SrcMAC string `json:"src_mac"` | ||
SrcPort int64 `json:"src_port"` | ||
DestIP string `json:"dest_ip"` | ||
DstMAC string `json:"dst_mac"` | ||
DestPort int64 `json:"dest_port"` | ||
Proto string `json:"proto"` | ||
TxID int64 `json:"tx_id"` | ||
AppProto string `json:"app_proto"` | ||
Host string `json:"host"` | ||
Usgip string `json:"usgip"` | ||
UniqueAlertid string `json:"unique_alertid"` | ||
UsgipCountry string `json:"usgipCountry"` | ||
SrcipASN string `json:"srcipASN"` | ||
DstipASN string `json:"dstipASN"` | ||
UsgipASN string `json:"usgipASN"` | ||
Catname string `json:"catname"` | ||
InnerAlertAction string `json:"inner_alert_action"` | ||
InnerAlertGid int64 `json:"inner_alert_gid"` | ||
InnerAlertSignatureID int64 `json:"inner_alert_signature_id"` | ||
InnerAlertRev int64 `json:"inner_alert_rev"` | ||
InnerAlertSignature string `json:"inner_alert_signature"` | ||
InnerAlertCategory string `json:"inner_alert_category"` | ||
InnerAlertSeverity int64 `json:"inner_alert_severity"` | ||
NumSta int64 `json:"num_sta"` | ||
ApFrom string `json:"ap_from"` | ||
ApTo string `json:"ap_to"` | ||
Name string `json:"name"` | ||
} | ||
|
||
type UnifiSiteUsers map[string]UnifiUsers | ||
|
||
type UnifiUsers struct { | ||
Meta Meta `json:"meta"` | ||
Users []UnifiUser `json:"data"` | ||
} | ||
|
||
type UnifiUser struct { | ||
ID string `json:"_id"` | ||
Mac string `json:"mac"` | ||
SiteID string `json:"site_id"` | ||
Oui string `json:"oui"` | ||
IsGuest bool `json:"is_guest"` | ||
FirstSeen int64 `json:"first_seen"` | ||
LastSeen int64 `json:"last_seen"` | ||
IsWired bool `json:"is_wired"` | ||
Hostname string `json:"hostname"` | ||
} | ||
|
||
type UnifiSiteDevices map[string]UnifiDevices | ||
|
||
type UnifiDevices struct { | ||
Meta Meta `json:"meta"` | ||
Devices []UnifiDevice `json:"data"` | ||
} | ||
|
||
type UnifiDevice struct { | ||
ID string `json:"_id"` | ||
Mac string `json:"mac"` | ||
State int64 `json:"state"` | ||
Adopted bool `json:"adopted"` | ||
Disabled bool `json:"disabled"` | ||
Type string `json:"type"` | ||
Model string `json:"model"` | ||
Name string `json:"name"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module github.com/ryancurrah/unifi-notifications | ||
|
||
go 1.12 | ||
|
||
require ( | ||
github.com/caarlos0/env v3.5.0+incompatible | ||
github.com/gorilla/websocket v1.4.0 // indirect | ||
github.com/lusis/go-slackbot v0.0.0-20180109053408-401027ccfef5 // indirect | ||
github.com/lusis/slack-test v0.0.0-20190426140909-c40012f20018 // indirect | ||
github.com/nlopes/slack v0.5.0 | ||
github.com/pkg/errors v0.8.1 // indirect | ||
github.com/prometheus/common v0.9.1 | ||
github.com/sirupsen/logrus v1.4.2 | ||
golang.org/x/sys v0.0.0-20190520201301-c432e742b0af // indirect | ||
) |
Oops, something went wrong.