-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from franky47/feat/cachet
Add Cachet-based services
- Loading branch information
Showing
3 changed files
with
86 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,69 @@ | ||
import axios, { AxiosResponse } from 'axios' | ||
import { SettingsState } from '../../types' | ||
import Service from '../service' | ||
import Status from '../status' | ||
|
||
// https://docs.cachethq.io/docs/component-statuses | ||
enum CachetComponentStatus { | ||
OPERATIONAL = 1, // The component is working. | ||
PERFORMANCE_ISSUES = 2, // The component is experiencing some slowness. | ||
PARTIAL_OUTAGE = 3, // The component may not be working for everybody. This could be a geographical issue for example. | ||
MAJOR_OUTAGE = 4, // The component is not working for anybody. | ||
} | ||
|
||
interface CachetComponent { | ||
enabled: boolean | ||
status: CachetComponentStatus | ||
} | ||
|
||
type CachetComponentsResponse = AxiosResponse<{ | ||
// todo: Handle pagination. | ||
// By default only the first 20 components are monitored. | ||
meta: any | ||
data: CachetComponent[] | ||
}> | ||
|
||
// -- | ||
|
||
class CachetService extends Service { | ||
constructor(name: string, domain: string) { | ||
super(name, domain) | ||
} | ||
|
||
async updateStatus(settings: SettingsState) { | ||
const components = await axios.get<any, CachetComponentsResponse>( | ||
`${this.domain}/api/v1/components` | ||
) | ||
|
||
const status = components?.data?.data?.reduce<CachetComponentStatus>( | ||
(highestStatus, component) => | ||
component.enabled | ||
? Math.max(highestStatus, component.status) | ||
: highestStatus, // skip disabled components | ||
CachetComponentStatus.OPERATIONAL | ||
) | ||
|
||
switch (status) { | ||
case CachetComponentStatus.OPERATIONAL: | ||
this.status = Status.OPERATIONAL | ||
break | ||
case CachetComponentStatus.PERFORMANCE_ISSUES: | ||
this.status = Status.MINOR | ||
break | ||
case CachetComponentStatus.PARTIAL_OUTAGE: | ||
this.status = Status.PARTIAL | ||
break | ||
case CachetComponentStatus.MAJOR_OUTAGE: | ||
this.status = Status.MAJOR | ||
break | ||
default: | ||
this.status = Status.OPERATIONAL | ||
break | ||
} | ||
|
||
this.triggerNotification(settings) | ||
this.prevStatus = this.status | ||
} | ||
} | ||
|
||
export default CachetService |
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,11 @@ | ||
import CachetService from '../base/cachet' | ||
|
||
class CleverCloud extends CachetService { | ||
constructor() { | ||
const name = 'Clever Cloud' | ||
const url = 'https://www.clevercloudstatus.com' | ||
super(name, url) | ||
} | ||
} | ||
|
||
export default CleverCloud |
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