Skip to content

Commit

Permalink
Merge pull request #6 from stakater/update-readme
Browse files Browse the repository at this point in the history
[STK-114] Add "How to add new monitor" section in readme
  • Loading branch information
hazim1093 authored Feb 27, 2018
2 parents b98a809 + 8bf447a commit fa39f2e
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,51 @@ kubectl apply -f configmap.yaml -n <namespace>
kubectl apply -f rbac.yaml -n <namespace>
kubectl apply -f deployment.yaml -n <namespace>
```

## Adding support for a new Monitor

You can easily implement a new monitor and use it via the controller. First of all, you will need to create a new service struct that implements the following monitor service interface

```go
type MonitorService interface {
GetAll() []Monitor
Add(m Monitor)
Update(m Monitor)
GetByName(name string) (*Monitor, error)
Remove(m Monitor)
Setup(apiKey string, url string, alertContacts string)
}
```

Once the implementation of your service is done, you have to open up `monitor-proxy.go` and add a new case inside `OfType` method for your new monitor. Lets say you have named your service `MyNewMonitorService`, then you have to add the case like in the example below:

```go
func (mp *MonitorServiceProxy) OfType(mType string) MonitorServiceProxy {
mp.monitorType = mType
switch mType {
case "UptimeRobot":
mp.monitor = &UpTimeMonitorService{}
case "MyNewMonitor":
mp.monitor = &MyNewMonitorService{}
default:
log.Panic("No such provider found")
}
return *mp
}
```

Note that the name you specify here for the case will be the key for your new monitor which you can add it in ConfigMap.

Also in case of handling custom api objects for the monitor api, you can create mappers that map from the api objects to the generic `Monitor` objects. The way you have to create these is to create a file named `monitorname-mappers.go` and add mapping functions in that file. An example of a mapping function is found below:

```go
func UptimeMonitorMonitorToBaseMonitorMapper(uptimeMonitor UptimeMonitorMonitor) *Monitor {
var m Monitor
m.name = uptimeMonitor.FriendlyName
m.url = uptimeMonitor.URL
m.id = strconv.Itoa(uptimeMonitor.ID)
return &m
}
```

0 comments on commit fa39f2e

Please sign in to comment.