PHP code example of cmdrsharp / hetrixtools-api

1. Go to this page and download the library: Download cmdrsharp/hetrixtools-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cmdrsharp / hetrixtools-api example snippets


// Example Uptime Monitor creation (adding a ping monitor to 8.8.8.8)
use CmdrSharp\HetrixtoolsApi\Uptime\Factory as HetrixTools;

$monitor = new HetrixTools('myApiKey');

try {
	$result = $monitor->type('service')
	    ->name('Greatest Monitor')
	    ->target('8.8.8.8')
	    ->timeout(10)
	    ->frequency(1)
	    ->failsBeforeAlert(1)
	    ->public(false)
	    ->showTarget(false)
	    ->locations([
	        'dal' => true,
	        'msw' => true,
	        'nyc' => true
	    ])->create();
} catch(\Exception $e) {
	print($e->getMessage());
}

// Example Blacklist Monitor creation (adding a monitor to 192.168.0.0/24)
use CmdrSharp\HetrixtoolsApi\Blacklist\Factory as HetrixTools;

$monitor = new HetrixTools('myApiKey');

try {
	$result = $monitor->target('192.168.0.0/24')
	    ->label('Blacklist Monitor 1')
	    ->contact(1)
	    ->create();
} catch(\Exception $e) {
	print($e->getMessage());
}

// Example Listing Uptime Monitors
use CmdrSharp\HetrixtoolsApi\Uptime\Repository as HetrixTools;

$instance = new HetrixTools('myApiKey');

try {
	$result = $instance->listUptimeMonitors(); // Fetches 100 results
	$result = $instance->listUptimeMonitors(0, 50); // Page 0, 50 results per page.
} catch(\Exception $e) {
	print($e->getMessage());
}

// Example Blacklist Report
use CmdrSharp\HetrixtoolsApi\Blacklist\Repository as HetrixTools;

$instance = new HetrixTools('myApiKey');

try {
	$result = $instance->blacklistReport('8.8.8.8');
	$result = $instance->blacklistReport('8.8.8.8', '2018-03-29');
} catch(\Exception $e) {
	print($e->getMessage());
}

$result->getStatusCode(); // 200
$result->getBody(); // {"status":"SUCCESS","monitor_id":"exampleMonitorId","action":"added"}

// Example for modifying Uptime Monitors
try {
	// Changing the target, category and locations
	$result = $monitor->id('exampleMonitorId')
	    ->target('8.8.4.4')
	    ->category('My awesome monitor')
	    ->locations([
	        'dal' => true,
	        'msw' => true,
	        'nyc' => true,
	        'mos' => true
	    ])->patch();

	// Changing the name only.
	$result = $monitor->id('exampleMonitorId')
		->name('New awesome monitor')
		->patch();

} catch(\Exception $e) {
	print($e->getMessage());
}

// Example for modifying Blacklist Monitors
try {
	$result = $monitor->target('192.168.0.0/24')
	    ->label('Blacklist Monitor 113')
	    ->contact(5)
	    ->patch();
} catch(\Exception $e) {
	print($e->getMessage());
}


// Common Methods (for both Blacklist and Uptime)
create();
patch();
delete();
target(String $target);
listMonitors(?int $page = null, ?int $per_page = null);
listContacts();

// FACTORY: Uptime Monitoring Methods
id(String $id);
type(String $type);
name(String $name);
timeout(int $timeout);
frequency(int $frequency);
failsBeforeAlert(int $fails);
failedLocations(int $failed);
contactList(int $contactList);
category(String $category);
alertAfter(int $time);
repeatTimes(int $times);
repeatEvery(int $every);
public(bool $public);
showTarget(bool $show);
verify_ssl_certificate(bool $verify);
verify_ssl_host(bool $verify);
locations(array $locations);
keyword(String $keyword);
maxRedirects(int $redirects);
port(int $port);
checkAuth(bool $check);
smtpUser(String $user);
smtpPass(String $pass);

// REPOSITORY: Uptime Monitoring Methods
status();
uptimeReport(String $id);

// FACTORY: Blacklist Monitoring Methods
label(String $label);
contact(int $contact);

// REPOSITORY: Blacklist Monitoring Methods
blacklistReport(String $target, ?String $date = null);
manualCheck(String $target);