├── .gitignore
├── README.md
├── index.php
└── LICENSE
/.gitignore:
--------------------------------------------------------------------------------
1 | /temple.html
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # UptimeRobot-Page
2 |
3 | A status page based on [UptimeRobot](https://uptimerobot.com)
4 |
5 | 
6 | 
7 |
8 | ## 环境要求
9 |
10 | * PHP version >= 5.4
11 | * UptimeRobot 账户
12 |
13 | ## 部署
14 |
15 | ```bash
16 | curl -O https://raw.githubusercontent.com/fhyuncai/UptimeRobot-Page/master/index.php
17 | ```
18 |
19 | ## 配置
20 |
21 | 在 `index.php` 文件中的 `Configuration` 部分进行配置。
22 |
23 | ## 监控组
24 |
25 | 此状态页支持分组监控,默认格式为 `组/名称` ,在 UptimeRobot 控制台内设置形如此格式的 Friendly Name。
26 |
--------------------------------------------------------------------------------
/index.php:
--------------------------------------------------------------------------------
1 | ';
42 | } else {
43 | echo updateData();
44 | }
45 | } else {
46 | echo updateData();
47 | }
48 | }
49 |
50 |
51 | function updateData()
52 | {
53 | global $_configPageTitle;
54 |
55 | $pageViewContent = '';
56 | $dates = [];
57 | $ranges = '';
58 | $group = [];
59 |
60 | $startTimeStamp = strtotime(date('Ymd', strtotime('-30 days')));
61 | $endTimeStamp = strtotime(date('Ymd'));
62 |
63 | for ($d = 0; $d < 30; $d++) {
64 | $dates[] = date('Ymd', strtotime("-{$d} days"));
65 | }
66 | $dates = array_reverse($dates);
67 |
68 | foreach ($dates as $value) {
69 | $ranges .= strtotime($value) . '_' . strtotime('+1 days', strtotime($value)) . '-';
70 | }
71 | $ranges .= $startTimeStamp . '_' . $endTimeStamp;
72 |
73 | $requestApi = requestUptimerobot($startTimeStamp, $endTimeStamp, $ranges);
74 |
75 | $dataArr = json_decode($requestApi, true);
76 |
77 | if (isset($dataArr['stat']) && $dataArr['stat'] == 'ok') {
78 | $pageViewContent .= '
' . $_configPageTitle . '
状态更新于 ' . date('Y-m-d H:i') . '
';
80 | $pageViewContent .= '
';
169 | //$recordTimeEnd = explode(' ', microtime());
170 | //$pageViewContent .= '';
171 |
172 | file_put_contents(__DIR__ . '/cache_uptimepage.php', ' time(), 'content' => $pageViewContent], true) . ';');
173 |
174 | return $pageViewContent;
175 | } else {
176 | return 'Error: ' . $requestApi . PHP_EOL;
177 | }
178 | }
179 |
180 | function requestUptimerobot($start, $end, $ranges)
181 | {
182 | global $_configUptimerobotSecret;
183 |
184 | $ch = curl_init();
185 | curl_setopt($ch, CURLOPT_URL, 'https://api.uptimerobot.com/v2/getMonitors');
186 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
187 | curl_setopt($ch, CURLOPT_TIMEOUT, 10);
188 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
189 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
190 | curl_setopt($ch, CURLOPT_POST, 1);
191 | $postData = [
192 | 'api_key' => $_configUptimerobotSecret,
193 | 'format' => 'json',
194 | 'logs' => 1,
195 | 'logs_start_date' => $start,
196 | 'logs_end_date' => $end,
197 | 'custom_uptime_ranges' => $ranges
198 | ];
199 | curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
200 |
201 | $response = curl_exec($ch);
202 | $err = curl_error($ch);
203 | curl_close($ch);
204 | if (!empty($err)) {
205 | return false;
206 | } else {
207 | return $response;
208 | }
209 | }
210 |
211 | function formatDuration(int $seconds) {
212 | $minutes = 0;
213 | $hours = 0;
214 | if ($seconds >= 60) {
215 | $minutes = round($seconds / 60);
216 | $seconds = round($seconds % 60);
217 | if ($minutes >= 60) {
218 | $hours = round($minutes / 60);
219 | $minutes = round($minutes % 60);
220 | }
221 | }
222 | $text = "{$seconds} 秒";
223 | if ($minutes > 0) $text = "{$minutes} 分 {$text}";
224 | if ($hours > 0) $text = "{$hours} 小时 {$text}";
225 | return $text;
226 | }
227 |
228 | function checkJson($str)
229 | {
230 | if (is_null(json_decode($str))) return false;
231 | return true;
232 | }
233 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.