1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- require_once FRAMEWORK_PATH . 'protected/extensions/function_extend.php';
- require_once FRAMEWORK_PATH . 'protected/extensions/format_extend.php';
- function getAwsSeverIp() {
- $output = array();
- $return_var = array();
- $ret = exec("ifconfig", $output, $return_var);
- $ips = [];
- foreach ($output as $row) {
- $matches = [];
- preg_match('/inet addr:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/', $row, $matches);
- if ($matches) {
- $ip = $matches[1];
- $ips[$ip] = $ip;
- }
- }
- unset($ips['127.0.0.1']);
- return current($ips);
- }
- /**
- * 发送告警信息
- */
- function alermErrorMsg($msg) {
- Tool::err($msg);
- if (ENV == ENV_DEV) {
- Eos::log("【error】$msg");
- return false;
- }
- $msg = trim($msg);
- if (empty($msg)) {
- return false;
- }
- $amc_url = 'http://61.160.36.226/default/recordMsg';
- $data = [
- "code"=> CODE_UNKNOW_ERROT,
- "code_msg"=> $msg,
- "app_id"=> 'dw_box',
- "server_ip"=> getAwsSeverIp() ?: '127.0.0.1',
- "alerm_type"=> 'ERROR',
- "time"=> time()
- ];
- $appKey = 'a67362f15b13cf5df4ac695b39844c84';
- $tmpArr = $data;
- $tmpArr['app_key'] = $appKey;
- sort($tmpArr, SORT_STRING);
- $tmpStr = implode($tmpArr);
- $signStr = sha1($tmpStr);
- $data['sign'] = $signStr;
- $header = 'Host: amc-admin.duowan.com';
- $ret = (new dwHttp)->post($amc_url, $data, 5, $header);
- $ret = json_decode($ret, true);
- if ($ret['result']) {
- return true;
- } else {
- var_dump("【error】告警错误:" . $ret['msg']);
- return false;
- }
- }
|