-
Notifications
You must be signed in to change notification settings - Fork 9
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
Showing
7 changed files
with
239 additions
and
84 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,7 @@ | ||
version: '2' | ||
|
||
services: | ||
redis: | ||
image: redis:latest | ||
ports: | ||
- '127.0.0.1:6379:6379' |
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
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,36 @@ | ||
package src | ||
|
||
import ( | ||
"github.com/go-redis/redis" | ||
"time" | ||
) | ||
|
||
type Incident struct { | ||
Id string | ||
Time time.Time | ||
Title string | ||
Resolved time.Time | ||
} | ||
|
||
type IncidentUpdate struct { | ||
Id string | ||
Incident string | ||
Status string | ||
Message string | ||
} | ||
|
||
type Incidents struct { | ||
db redis.Client | ||
} | ||
|
||
func (i *Incidents) Initialize(db redis.Client) { | ||
i.db = db | ||
} | ||
|
||
func (i *Incidents) CreateIncident(incident Incident) error { | ||
return nil | ||
} | ||
|
||
func (i *Incidents) CreateIncidentUpdate(incident string, update IncidentUpdate) error { | ||
return nil | ||
} |
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,80 @@ | ||
package src | ||
|
||
import ( | ||
"github.com/go-redis/redis" | ||
"encoding/json" | ||
) | ||
|
||
const REDIS_MAP = "statuspage_services" | ||
|
||
type Service struct { | ||
ID string | ||
Name string | ||
Status string | ||
Description string | ||
Group string | ||
Link string | ||
Tags []string | ||
Enabled bool | ||
} | ||
|
||
type Services struct { | ||
db redis.Client | ||
} | ||
|
||
func (s *Services) Initialize(db redis.Client) { | ||
s.db = db | ||
} | ||
|
||
func (s *Services) InsertService(id string, service Service) error { | ||
serialized, err := json.Marshal(service) | ||
if err != nil { return err } | ||
|
||
if err := s.db.HSet(REDIS_MAP, id, serialized).Err(); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (s *Services) RemoveService(id string) error { | ||
err := s.db.HDel(REDIS_MAP, id).Err() | ||
return err | ||
} | ||
|
||
func (s *Services) GetServices(enabled bool) ([]Service, error) { | ||
services := []Service{} | ||
|
||
results, err := s.db.HGetAll(REDIS_MAP).Result() | ||
if err != err { | ||
return nil, err | ||
} | ||
|
||
for id, result := range results { | ||
var service Service | ||
if err := json.Unmarshal([]byte(result), &service); err != nil { | ||
return nil, err | ||
} | ||
service.ID = id | ||
|
||
if service.Enabled == enabled { | ||
services = append(services, service) | ||
} | ||
} | ||
|
||
return services, nil | ||
} | ||
|
||
func (s *Services) GetService(id string) (Service, error){ | ||
result, err := s.db.HGet(REDIS_MAP, id).Result() | ||
if err != err { | ||
return Service{}, err | ||
} | ||
|
||
var service Service | ||
if err := json.Unmarshal([]byte(result), &service); err != nil { | ||
return Service{}, err | ||
} | ||
|
||
return service, nil | ||
} |
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,50 @@ | ||
package src | ||
|
||
|
||
/* | ||
* Aggregate and group services by service group. | ||
*/ | ||
|
||
type AggregatedServices map[string][]Service | ||
|
||
func AggregateServices (services []Service) AggregatedServices { | ||
aggregated := AggregatedServices{} | ||
|
||
for _, service := range services { | ||
groupName := service.Group | ||
|
||
group := aggregated[groupName] | ||
if group != nil { | ||
group = append(group, service) | ||
} else { | ||
group = []Service{service} | ||
} | ||
aggregated[groupName] = group | ||
} | ||
|
||
return aggregated | ||
} | ||
|
||
/* | ||
* Extract the most critical service. | ||
*/ | ||
|
||
func MostCriticalStatus(services []Service) int { | ||
statusValues := map[string]int{ | ||
"Operational": 0, | ||
"Performance Issues": 1, | ||
"Partial Outage": 2, | ||
"Major Outage": 3, | ||
} | ||
|
||
mostCritical := 0 | ||
|
||
for _, service := range services { | ||
serviceStatus := statusValues[service.Status] | ||
if serviceStatus > mostCritical { | ||
mostCritical = serviceStatus | ||
} | ||
} | ||
|
||
return mostCritical | ||
} |
This file was deleted.
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