Skip to content

Commit 466a414

Browse files
author
zng
committed
支持Checks
1 parent 7a57a0d commit 466a414

File tree

2 files changed

+63
-44
lines changed

2 files changed

+63
-44
lines changed

Seefan/Service/Checks.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
namespace Seefan\Service;
3+
class Checks extends Service
4+
{
5+
public function __construct($base_url, $http)
6+
{
7+
parent::__construct($base_url, $http);
8+
$this->name = 'checks';
9+
}
10+
}

test.php

Lines changed: 53 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,66 +6,75 @@
66
* Time: 10:22
77
*/
88
require 'Seefan\ConsulClient.php';
9-
$cc = new Seefan\ConsulClient(['host' => '10.20.28.51:8500']);
9+
$cc = new Seefan\ConsulClient(['host' => '192.168.56.101:8500']);
1010
//var_dump( $cc->catalog->services());
1111
//var_dump($cc->kv->get('service/0000'));
1212
//var_dump($cc->agent->self());
1313
//echo $cc->kv->set('test/test1', 'zng');
1414
//$cc->kv->delete('test/test1');
1515
$str = '{
1616
"ID": "redis1",
17-
"Name": "redis",
17+
"Name": "scene",
1818
"Tags": [
1919
"primary",
2020
"v1"
2121
],
2222
"Address": "127.0.0.1",
2323
"Port": 8000,
24-
"EnableTagOverride": false
24+
"EnableTagOverride": false,
25+
"Check": {
26+
"DeregisterCriticalServiceAfter": "90m",
27+
"HTTP": "http://localhost:5000/health",
28+
"Interval": "10s",
29+
"TTL": "10s"
30+
}
2531
}';
26-
//$param = json_decode($str, true);
27-
//var_dump($cc->agent->service('register', $param));
28-
//$rsp=$cc->agent->service('deregister','redis1');
29-
//$rsp=$cc->catalog->service('XE');
3032

31-
$json_str = '{
32-
"Datacenter": "dc1",
33-
"ID": "40e4a748-2192-161a-0510-9bf59fe950b5",
34-
"Node": "foobar",
35-
"Address": "192.168.10.10",
36-
"TaggedAddresses": {
37-
"lan": "192.168.10.10",
38-
"wan": "10.0.10.10"
39-
},
40-
"NodeMeta": {
41-
"somekey": "somevalue"
42-
},
43-
"Service": {
44-
"ID": "redis1",
45-
"Service": "redis",
46-
"Tags": [
47-
"primary",
48-
"v1"
49-
],
50-
"Address": "127.0.0.1",
51-
"Port": 8000
52-
},
53-
"Check": {
54-
"Node": "foobar",
55-
"CheckID": "service:redis1",
56-
"Name": "Redis health check",
57-
"Notes": "Script based health check",
58-
"Status": "passing",
59-
"ServiceID": "redis1"
60-
}
61-
}';
33+
$rsp=$cc->agent->service('deregister','redis1');
34+
$param = json_decode($str, true);
35+
$rsp = $cc->agent->service('register', $param);
36+
//$rsp=$cc->catalog->service('XE');,
37+
38+
//$json_str = '{
39+
// "Datacenter": "dc1",
40+
// "ID": "40e4a748-2192-161a-0510-9bf59fe950b5",
41+
// "Node": "foobar",
42+
// "Address": "192.168.10.10",
43+
// "TaggedAddresses": {
44+
// "lan": "192.168.10.10",
45+
// "wan": "10.0.10.10"
46+
// },
47+
// "NodeMeta": {
48+
// "somekey": "somevalue"
49+
// },
50+
// "Service": {
51+
// "ID": "redis1",
52+
// "Service": "redis",
53+
// "Tags": [
54+
// "primary",
55+
// "v1"
56+
// ],
57+
// "Address": "127.0.0.1",
58+
// "Port": 8000
59+
// },
60+
// "Check": {
61+
// "Node": "foobar",
62+
// "CheckID": "service:redis1",
63+
// "Name": "Redis health check",
64+
// "Notes": "Script based health check",
65+
// "Status": "passing",
66+
// "ServiceID": "redis1"
67+
// }
68+
// }';
6269
//$json = json_decode($json_str, true);
6370
//$rsp = $cc->catalog->register($json);
6471

65-
$json_str='{
66-
"Datacenter": "dc1",
67-
"Node": "foobar"
68-
}';
69-
$json = json_decode($json_str, true);
70-
$rsp = $cc->catalog->deregister($json);
72+
//$json_str='{
73+
// "Datacenter": "dc1",
74+
// "Node": "foobar"
75+
//}';
76+
//$json = json_decode($json_str, true);
77+
//$rsp = $cc->catalog->deregister($json);
78+
79+
//$rsp=$cc->agent->checks();
7180
var_dump($rsp);

0 commit comments

Comments
 (0)