documentation

This commit is contained in:
2013-08-25 22:27:20 +02:00
parent fc7ea237b6
commit 4ce3e726c5
2 changed files with 233 additions and 9 deletions
+227 -3
View File
@@ -1,14 +1,238 @@
# UptimeSharp
> Under development - don't use yet!
**UptimeSharp** is a C#.NET class library that integrates the [UptimeRobot API](http://http://www.uptimerobot.com/api.asp).
**UptimeSharp** is a C#.NET class library, that integrates the [UptimeRobot API](http://http://www.uptimerobot.com/api.asp).
The wrapper consists of 2 parts:
- Get and modify monitors
- Get and modify alert contacts
[uptimesharp.frontendplay.com](http://uptimesharp.frontendplay.com/) (coming soon)
## Install using NuGet
```
Install-Package UptimeSharp
```
[nuget.org/packages/UptimeSharp](https://www.nuget.org/packages/UptimeSharp/) (coming soon)
## Usage Example
Get your [API Key UptimeRobot](http://uptimerobot.com/mySettings.asp) (left section under "API Information")
Include the UptimeSharp namespace and it's associated models:
```csharp
using UptimeSharp;
using UptimeSharp.Models;
```
Initialize UptimeClient with:
```csharp
UptimeClient _client = new UptimeClient("[YOUR_API_KEY]");
```
Do a simple request - e.g. get all your monitors:
```csharp
_client.GetMonitors().ForEach(
item => Console.WriteLine(item.Name + " | " + item.Type)
);
```
Which will output:
frontendplay | HTTP
google | Keyword
localhost | Ping
...
## Constructor
```csharp
UptimeClient(string apiKey)
```
Get your [API Key UptimeRobot](http://uptimerobot.com/mySettings.asp) (left section under "API Information")
## Retrieve
Get list of all monitors:
```csharp
List<Monitor> items = _client.GetMonitors();
```
Get monitors by ID - or a single monitor:
```csharp
List<Monitor> items = _client.GetMonitors(new int[]{ 12891, 98711 });
// or
Monitor item = _client.GetMonitor(12891);
```
Provide additional params for more data:
```csharp
List<Monitor> items = _client.GetMonitors(
monitorIDs: new int[]{ 12891, 98711 },
// the number of days to calculate the uptime ratio(s) for
customUptimeRatio: new float[] { 7, 30, 45 },
// include log, if true (default: false)
showLog: true,
// include alerts, if true (default: true)
showAlerts = true
);
```
`monitorIDs`: You can remove this parameter if you want to retrieve all monitors _(default: null)_
<br>
`customUptimeRatio`: the number of days to calculate the uptime ratio(s) for _(default: null)_
<br>
`showLog`: include log, if true _(default: false)_
<br>
`showAlerts`: include alerts, if true _(default: true)_
<br>
## Add
Adds/creates a new monitor.
```csharp
bool AddMonitor(
string name,
string uri,
Type type = Type.HTTP,
Subtype subtype = Subtype.Unknown,
int? port = null,
string keywordValue = null,
KeywordType keywordType = KeywordType.Unknown,
int[] alerts = null,
string HTTPUsername = null,
string HTTPPassword = null
)
```
Example - Watch the a SMTP Server:
```csharp
bool isSuccess = _client.AddMonitor(
name: "cee",
uri: "127.0.0.1",
type: Type.Port,
subtype: Subtype.SMTP
);
```
`name`: A friendly name for the new monitor
<br>
`uri`: The URI or IP to watch
<br>
`type`: The type of the monitor (see [# Monitor Types](#monitor-types))
<br>
`subtype`: The subtype of the monitor (only for Type.Port) (see [# Monitor Types](#monitor-types))
<br>
`port`: The port (only for Subtype.Custom)
<br>
`keywordValue`: The keyword value (for Type.Keyword)
<br>
`keywordType`: Type of the keyword (for Type.Keyword)
<br>
`alerts`: An ID list of existing alerts to notify
<br>
`HTTPUsername`: The HTTP username
<br>
`HTTPPassword`: The HTTP password
As you can see, a lot of these parameters are only available if you've specified the correct `Type`.
<br>
If you've selected `Type.Port` for example, UptimeSharp will ignore the `keywordValue` and `keywordType` parameters, even if you submitted valid ones.
## Delete
Delete a monitor by ID:
```csharp
bool isSuccess = _client.DeleteMonitor(12891);
```
Delete a monitor by a Monitor instance:
```csharp
// Monitor myMonitor = ...
bool isSuccess = _client.DeleteMonitor(myMonitor);
```
## Modify
In order to modify an existing monitor, just alter the properties of the Monitor instance and call the `ModifyMonitor` method:
```csharp
// Monitor myMonitor = ...
myMonitor.Name = "my new name :-)";
bool isSuccess = _client.ModifyMonitor(myMonitor);
```
**Important:** It is not possible to alter the `Type` of a monitor after its creation! In case you want to do this, you have to delete the monitor and create a new one with the changed type.
### Modify Alerts
Retrieve all alerts:
```csharp
List<Alert> items = _client.GetAlerts();
```
Retrieve alerts by IDs:
```csharp
List<Alert> items = _client.GetAlerts(new int[]{ 12897, 98711 });
```
Retrieve a specific alert:
```csharp
Alert item = _client.GetAlert(12897);
```
Adds an alert _(Due to UptimeRobot API limitations SMS and Twitter alert contact types are not supported yet)_:
```csharp
bool isSuccess = _client.AddAlert(AlertType.Email, "uptimesharp@outlook.com");
```
Adds an alert from instance:
```csharp
// Alert myAlert = ...
bool isSuccess = _client.AddAlert(myAlert);
```
Deletes an alert:
```csharp
bool isSuccess = _client.DeleteAlert(12897);
```
Deletes an alert from instance:
```csharp
// Alert myAlert = ...
bool isSuccess = _client.DeleteAlert(myAlert);
```
---
## Release History
- 2013-08-13 v0.1.0 initial
- 2013-08-25 v0.1.0 Monitor and Alert APIs
## Dependencies
+6 -6
View File
@@ -20,11 +20,11 @@ namespace UptimeSharp
/// <returns>
/// Monitor List
/// </returns>
public List<Monitor> GetMonitors(int[] monitors = null, float[] customUptimeRatio = null, bool showLog = false, bool showAlerts = true)
public List<Monitor> GetMonitors(int[] monitorIDs = null, float[] customUptimeRatio = null, bool showLog = false, bool showAlerts = true)
{
RetrieveParameters parameters = new RetrieveParameters()
{
Monitors = monitors,
Monitors = monitorIDs,
CustomUptimeRatio = customUptimeRatio,
ShowAlerts = showAlerts,
ShowLog = showLog
@@ -84,19 +84,19 @@ namespace UptimeSharp
/// <param name="name">The name of the new monitor.</param>
/// <param name="uri">The URI or IP to watch.</param>
/// <param name="type">The type of the monitor.</param>
/// <param name="subtype">The subtype of the port.</param>
/// <param name="subtype">The subtype of the monitor (if port).</param>
/// <param name="port">The port (only for Subtype.Custom).</param>
/// <param name="keywordValue">The keyword value.</param>
/// <param name="keywordType">Type of the keyword.</param>
/// <param name="alerts">A ID list of existing alerts to notify.</param>
/// <param name="HTTPPassword">The HTTP password.</param>
/// <param name="alerts">An ID list of existing alerts to notify.</param>
/// <param name="HTTPUsername">The HTTP username.</param>
/// <param name="HTTPPassword">The HTTP password.</param>
/// <returns>
/// Success state
/// </returns>
public bool AddMonitor(string name, string uri, Type type = Type.HTTP, Subtype subtype = Subtype.Unknown,
int? port = null, string keywordValue = null, KeywordType keywordType = KeywordType.Unknown,
int[] alerts = null, string HTTPPassword = null, string HTTPUsername = null)
int[] alerts = null, string HTTPUsername = null, string HTTPPassword = null)
{
MonitorParameters parameters = new MonitorParameters()