forked from Jord-JD/cachet.php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.php
More file actions
111 lines (90 loc) · 2.98 KB
/
Copy pathexamples.php
File metadata and controls
111 lines (90 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
require_once 'vendor/autoload.php';
use \DivineOmega\CachetPHP\Client\ApiV1Client;
use \DivineOmega\CachetPHP\Factories\CachetInstanceFactory;
$client = new ApiV1Client('https://demo.cachethq.io/api', '9yMHsdioQosnyVK4iCVR');
$cachetInstance = CachetInstanceFactory::create($client);
// Check if Cachet instance is working correctly
if ($cachetInstance->isWorking()) {
echo "\n";
echo '*** Cachet instance working fine! ***';
echo "\n";
}
// Add component
echo "\n";
echo '*** Add Component ***';
echo "\n";
$componentDetails = ['name' => 'Test Component '.rand(1, 99999), 'status' => 1];
$component = $cachetInstance->createComponent($componentDetails);
echo $component->id.' - '.$component->name.' - '.$component->description.' - '.$component->status;
echo "\n";
// Get components
$components = $cachetInstance->getAllComponents();
// Display components
echo "\n";
echo '*** Components ***';
echo "\n";
foreach ($components as $component) {
echo $component->id.' - '.$component->name.' - '.$component->description.' - '.$component->status;
echo "\n";
}
// Get components sorted by name ascending
$components = $cachetInstance->getAllComponents('name', 'asc');
// Display components sorted by name ascending
echo "\n";
echo '*** Components (sorted by name ascending) ***';
echo "\n";
foreach ($components as $component) {
echo $component->id.' - '.$component->name.' - '.$component->description.' - '.$component->status;
echo "\n";
}
// Get components sorted by name descending
$components = $cachetInstance->getAllComponents('name', 'desc');
// Display components sorted by name descending
echo "\n";
echo '*** Components (sorted by name descending) ***';
echo "\n";
foreach ($components as $component) {
echo $component->id.' - '.$component->name.' - '.$component->description.' - '.$component->status;
echo "\n";
}
// Get incidents
$incidents = $cachetInstance->getAllIncidents();
// Display incidents
echo "\n";
echo '*** Incidents ***';
echo "\n";
foreach ($incidents as $incident) {
echo $incident->id.' - '.$incident->name.' - '.$incident->message.' - '.$incident->human_status;
echo "\n";
}
// Get metrics
$metrics = $cachetInstance->getAllMetrics();
// Display metrics
echo "\n";
echo '*** Metrics ***';
echo "\n";
foreach ($metrics as $metric) {
echo $metric->id.' - '.$metric->name;
echo "\n";
}
// Get metric points for first metric
$metricPoints = $metrics[0]->getAllMetricPoints();
// Display metric points
echo "\n";
echo '*** Metric points (for Metric ID '.$metrics[0]->id.') ***';
echo "\n";
foreach ($metricPoints as $metricPoint) {
echo $metricPoint->id.' - Created at: '.$metricPoint->created_at.' - Updated at: '.$metricPoint->updated_at.' - Value: '.$metricPoint->value;
echo "\n";
}
// Get subscribers
$subscribers = $cachetInstance->getAllSubscribers();
// Display subscribers
echo "\n";
echo '*** Subscribers ***';
echo "\n";
foreach ($subscribers as $subscriber) {
echo $subscriber->id.' - '.$subscriber->email;
echo "\n";
}