...
 
Commits (4)
......@@ -7,9 +7,13 @@ and this project adheres to [Semantic Versioning](semver.md).
## [Unreleased]
### Added
* First implementation
### Changed
### Deprecated
### Removed
### Fixed
### Security
\ No newline at end of file
### Security
## [0.1.0] - 2020-06-06
### Added
* First implementation
\ No newline at end of file
......@@ -70,8 +70,21 @@ At `/zabbix.php?action=userprofile.edit` add a Cachet item and type anything int
#### Install Bridge
You either have to make a Wrapper script which calls the Bridge,
or you can move the Binary and config.ini directly into `/usr/lib/zabbix/alertscripts/`
The Zabbix-Cachet-Bridge by default requires the `config.ini` to be next to it,
this can be changed by either using the `ZCB_CONFIG_PATH` environment variable or
by using a Wrapper Script.
Either the Executable or the Wrapper must be placed in `/usr/lib/zabbix/alertscripts/`.
You can check if everything is working as it should, by simply trying to start the tool manually.
This will do the following things:
* Open and parse the Config
* Open and init the Database
* Open and check a connection to Cachet
It will then fail saying its missing some arguments, if you see that notice, everything worked as it should!
#### Configure Bridge
......@@ -86,6 +99,10 @@ token = "<cachet token>"
driver="sqlite3"
file="/path/to/store/sqlite.db3"
[reporting]
minimum_severity = "Disaster"
notify_subscribers = true
[components]
<hostname> = <component id>
duiker1 = 23
......
......@@ -9,6 +9,10 @@ file="sqlite.db3"
[components]
<hostname> = <component id>
[reporting]
minimum_severity = "Disaster"
notify_subscribers = true
[messages]
new_issue = "**Overwatch detected a Critical issue, the Team has been Informed!**\n\n*This is a Automated action by The Overwatch*"
fixed_issue = "**Overwatch detected the Issue was fixed**\n\n*This is a Automated action by The Overwatch**"
\ No newline at end of file
......@@ -48,8 +48,8 @@ func Init(url string, token string) *cachet.Client {
panic(err)
}
if version.Major() != 1 && version.Minor() != 4 {
panic("Zabbix-Cachet-Bridge: Please note that this bridge only supports CachetHQ 1.4.0-development!")
if version.Major() != 2 && (version.Minor() != 4 && version.Minor() != 3) {
panic("Zabbix-Cachet-Bridge: Please note that this bridge only supports CachetHQ 2.3.0 and 2.4.0!")
}
return client
......
......@@ -15,30 +15,45 @@ import (
"atvg-studios.com/zabbix-cachet-bridge/src/database"
"atvg-studios.com/zabbix-cachet-bridge/src/zabbix"
"encoding/json"
"fmt"
cachet2 "github.com/andygrunwald/cachet"
"gopkg.in/ini.v1"
"os"
"strings"
)
// Zabbix-Cachet-Bridge 0.1.0
func main() {
cfg, e := ini.Load("config.ini")
// Stage 1: Load the Config file
fpath := os.Getenv("ZCB_CONFIG_PATH")
var cfg *ini.File
var e error
if len(fpath) >= 1 {
cfg, e = ini.Load(fpath)
} else {
cfg, e = ini.Load("config.ini")
}
if e != nil {
panic(e)
}
// Stage 2: Connect and Initialize the Database
db := database.Init2(cfg)
db.Schema()
args := os.Args
// Stage 3: Connect to and check the Cachet API
capi := cachet.Init2(cfg)
// Stage 4: Check that we have 2 arguments
args := os.Args
if len(args) != 2 {
println("zabbix-cachet-bridge requires 2 arguments: \"Message Title\" \"{Message JSON}\"")
os.Exit(1)
}
// Stage 5: Get and parse arguments
title := args[1]
zabbixJson := args[2]
......@@ -53,6 +68,9 @@ func main() {
if e != nil {
panic(e)
}
if hostId <= 0 {
panic(fmt.Sprintf("No ComponentID Mapping for hostname '%s'", status.Host))
}
severity := zabbix.GetCachetSeverity(status.Severity)
......@@ -63,12 +81,17 @@ func main() {
statusId = cachet.StatusFixed
}
capi := cachet.Init2(cfg)
newIssueMessage := cfg.Section("messages").Key("new_issue").String()
fixedIssueMessage := cfg.Section("messages").Key("fixed_issue").String()
minimumSeverity := zabbix.GetCachetSeverity(cfg.Section("reporting").Key("minimum_severity").String())
// Stage 6: Run Incident Create routine if applicable
if statusId == cachet.StatusInvestigating && severity >= minimumSeverity {
notifySubs, e := cfg.Section("reporting").Key("notify_subscribers").Bool()
if e != nil {
panic(e)
}
if statusId == cachet.StatusInvestigating && severity == cachet.StatusMajorOutage && hostId > 0 {
i := cachet2.Incident{
Status: statusId,
ComponentStatus: severity,
......@@ -76,7 +99,7 @@ func main() {
Message: newIssueMessage,
Name: title,
IsResolved: false,
Notify: false,
Notify: notifySubs,
}
i2, _, e := capi.Incidents.Create(&i)
......@@ -88,7 +111,8 @@ func main() {
db.OpenIssueForComponent(status.EventId, hostId, i2.ID)
}
if statusId == cachet.StatusFixed && hostId > 0 {
// Stage 7: Run Incident Close routine if applicable
if statusId == cachet.StatusFixed {
issue := db.GetIssueForComponent(status.EventId)
if issue < 0 {
......