To add a monitor on Netumo, first, log in to your account, then enter details including Name and URL, choose a protocol, and customise your notification settings for your new monitor to be created.
URL: https://api.netumo.app/api/Website/AddSimpleMonitor
Type (verb): POST
Content Type: application/json
Body: {
Name: <NAME>,
Protocol: <PROTOCOL HTTP/HTTPS etc>,
Url: <Full URL>,
EmailEnabled: <true or false>,
TwitterEnabled: <true or false>,
SlackEnabled: <true or false>,
MicrosoftTeamsEnabled: <true or false>,
TelegramEnabled: <true or false>,
SuppressSuccessEmail: <true or false>
}
HTML/Javascript source code example:
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<div class="row">
<div class="col-md-6">
<h4>Login </h4>
<div id="loginDiv">
<div class="form-group">
<label for="txtEmail">Email Address </label>
<input type='email' name="email" id="loginEmail" class="form-control">
</div>
<div class="form-group">
<label>Password</label>
<input type="password" id="loginPwd" class="form-control">
</div>
<div>
<button id="btnLogin" class="btn btn-default">Login</button>
</div>
</div>
<h4>Create Monitor </h4>
<div id="addMon">
<div class="form-group">
<label>Monitor Name</label>
<input type="text" id="Name" class="form-control">
</div>
<div class="form-group">
<label>Protocol</label>
<input type="text" id="Protocol" class="form-control">
</div>
<div class="form-group">
<label>URL</label>
<input type="url" id="URL" class="form-control">
</div>
<div class="form-group">
<label>Email notifications</label>
<input type="checkbox" id="EmailEnabled" class="form-control">
</div>
<div class="form-group">
<label>Twitter notifications</label>
<input type="checkbox" id="TwitterEnabled" class="form-control">
</div>
<div class="form-group">
<label>Slack notifications</label>
<input type="checkbox" id="SlackEnabled" class="form-control">
</div>
<div class="form-group">
<label>Microsoft Teams notifications</label>
<input type="checkbox" id="MicrosoftTeamsEnabled" class="form-control">
</div>
<div class="form-group">
<label>Telegram notifications</label>
<input type="checkbox" id="TelegramEnabled" class="form-control">
</div>
<div>
<button id="btnSubmit" class="btn btn-default">Create</button>
</div>
</div>
</div>
</div>
<div class="row">
<div>
<label id="msg"></label>
</div>
</div>
<script>
$(document).ready(function () {
$("#btnSubmit").on('click', function () {
var model = {
Name: $("#Name").val(),
Protocol: $("#Protocol").val(),
Url: $("#URL").val(),
EmailEnabled: $('#EmailEnabled').is(':checked') ? "true" : "false" ,
TwitterEnabled: $('#TwitterEnabled').is(':checked') ? "true" : "false",
SlackEnabled: $('#SlackEnabled').is(':checked') ? "true" : "false",
MicrosoftTeamsEnabled: $('#MicrosoftTeamsEnabled').is(':checked') ? "true" : "false",
TelegramEnabled: $('#TelegramEnabled').is(':checked') ? "true" : "false",
SuppressSuccessEmail: 'false'
}
$.ajax({
url: "https://api.netumo.app/api/Website/AddSimpleMonitor",
type: "POST",
headers: { 'Content-Type': 'application/json', 'Authorization' : 'Bearer ' + sessionStorage.getItem('accessToken') },
dataType: 'json',
data: JSON.stringify(model),
success: function (response) {
$("#Name").val("");
$("#Protocol").val("");
$("#URL").val("");
$("#EmailEnabled").val("");
$("#TwitterEnabled").val("");
$("#SlackEnabled").val("");
$("#MicrosoftTeamsEnabled").val("");
$("#TelegramEnabled").val("");
alert("Monitor Created!");
$("#msg").text(JSON.stringify(response));
},
error: function (jqXHR, textStatus, errorThrown) {
if (jqXHR.status == 417)
alert("Please verify your Email Address");
else if (jqXHR.status == 401)
alert("Access Denied");
else
alert(jqXHR.status);
}
})
});
$("#btnLogin").on('click', function () {
$.ajax({
url: "https://api.netumo.app/TOKEN",
type: "POST",
data: $.param({ grant_type: 'password', username: $("#loginEmail").val(), password: $("#loginPwd").val() }),
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
success: function (resp) {
sessionStorage.setItem('userName', resp.userName);
sessionStorage.setItem('accessToken', resp.access_token);
alert("Login Success");
},
error: function () {
alert("Login Failed!");
$("#msg").text("Authentication failed");
}
})
});
});
</script>
</body>
</html>
PHP source code example:
<?php
session_start();
?>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<div class="row">
<div class="col-md-6">
<form action = "/PHPCreateMonitor.php" method = "POST">
<h4>Login </h4>
<div id="loginDiv">
<div class="form-group">
<label for="txtEmail">Email Address </label>
<input type='email' name="username" id="loginEmail" class="form-control">
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="password" id="loginPwd" class="form-control">
</div>
<button id="btnLogin" class="btn btn-default">Login</button>
</div>
</form>
<form action = "/PHPCreateMonitor.php" method = "POST">
<h4>Create Monitor</h4>
<div id="addMon">
<div class="form-group">
<label>Monitor Name</label>
<input type="text" name = "name" id="Name" class="form-control">
</div>
<div class="form-group">
<label>Protocol</label>
<input type="text" name = "protocol" id="Protocol" class="form-control">
</div>
<div class="form-group">
<label>URL</label>
<input type="url" name = "url" id="URL" class="form-control">
</div>
<div class="form-group">
<label>Email notifications</label>
<input type="checkbox" name = "emailenabled" id="EmailEnabled" class="form-control">
</div>
<div class="form-group">
<label>Twitter notifications</label>
<input type="checkbox" name = "twitterenabled" id="TwitterEnabled" class="form-control">
</div>
<div class="form-group">
<label>Slack notifications</label>
<input type="checkbox" name = "slackenabled" id="SlackEnabled" class="form-control">
</div>
<div class="form-group">
<label>Microsoft Teams notifications</label>
<input type="checkbox" name = "microsoftteamsenabled" id="MicrosoftTeamsEnabled" class="form-control">
</div>
<div class="form-group">
<label>Telegram notifications</label>
<input type="checkbox" name = "telegramenabled" id="TelegramEnabled" class="form-control">
</div>
<div>
<button id="btnSubmit" name = "btnSubmit" class= "btn btn-default">Create</button>
</div>
</div>
</form>
</div>
</div>
<div class="row">
<div>
<label id="msg"></label>
</div>
</div>
<?php
if ((isset($_POST['username']) && $_POST['username']!="") && (isset($_POST['password']) && $_POST['password']!="")){
$username = $_POST['username'];
$password = $_POST['password'];
$data = array(
'grant_type' => 'password',
'username' => $username,
'password' => $password
);
$payload = http_build_query($data);
$url = "https://api.netumo.app/TOKEN";
$client = curl_init($url);
curl_setopt($client, CURLOPT_POSTFIELDS, $payload);
curl_setopt($client, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($client, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($client);
echo curl_error($client);
$result = json_decode($response);
$access_token = $result->access_token;
$_SESSION["authtoken"] = $access_token;
}
if(isset($_POST["btnSubmit"])){
$name = $_POST['name'];
$protocol = $_POST['protocol'];
$urlVar = $_POST['url'];
$email = isset($_POST['emailenabled']) ? $_POST['emailenabled'] : 'false';
$twitter = isset($_POST['twitterenabled']) ? $_POST['twitterenabled'] : 'false';
$slack = isset($_POST['slackenabled']) ? $_POST['slackenabled'] : 'false';
$microsoftteams = isset($_POST['microsoftteamsenabled']) ? $_POST['microsoftteamsenabled'] : 'false';
$telegram = isset($_POST['telegramenabled']) ? $_POST['telegramenabled'] : 'false';
if($email == 'on'){
$email = 'true';
}
if($twitter == 'on'){
$twitter = 'true';
}
if($slack == 'on'){
$slack = 'true';
}
if($microsoftteams == 'on'){
$microsoftteams = 'true';
}
if($telegram == 'on'){
$telegram = 'true';
}
$postRequest = array(
'Name' => $name,
'Protocol' => $protocol,
'URL' => $urlVar,
'EmailEnabled' => $email,
'TwitterEnabled' => $twitter,
'SlackEnabled' => $slack,
'MicrosoftTeamsEnabled' => $microsoftteams,
'TelegramEnabled' => $telegram,
'SuppressSuccessEmail' => 'false',
);
$url1 = "https://api.netumo.app/api/Website/AddSimpleMonitor";
$client = curl_init($url1);
curl_setopt($client, CURLOPT_POSTFIELDS, json_encode($postRequest));
curl_setopt($client, CURLOPT_RETURNTRANSFER, true);
$headers = array(
"Accept: application/json",
"Content-Type: application/json",
"Authorization: Bearer " . $_SESSION["authtoken"],
);
curl_setopt($client, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($client);
echo curl_error($client);
$result = json_decode($response);
echo "Check on your Netumo account to see your new Monitor";
}
?>