function_extend.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. require_once FRAMEWORK_PATH . 'protected/extensions/function_extend.php';
  3. require_once FRAMEWORK_PATH . 'protected/extensions/format_extend.php';
  4. function getAwsSeverIp() {
  5. $output = array();
  6. $return_var = array();
  7. $ret = exec("ifconfig", $output, $return_var);
  8. $ips = [];
  9. foreach ($output as $row) {
  10. $matches = [];
  11. preg_match('/inet addr:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/', $row, $matches);
  12. if ($matches) {
  13. $ip = $matches[1];
  14. $ips[$ip] = $ip;
  15. }
  16. }
  17. unset($ips['127.0.0.1']);
  18. return current($ips);
  19. }
  20. /**
  21. * 发送告警信息
  22. */
  23. function alermErrorMsg($msg) {
  24. Tool::err($msg);
  25. if (ENV == ENV_DEV) {
  26. Eos::log("【error】$msg");
  27. return false;
  28. }
  29. $msg = trim($msg);
  30. if (empty($msg)) {
  31. return false;
  32. }
  33. $amc_url = 'http://61.160.36.226/default/recordMsg';
  34. $data = [
  35. "code"=> CODE_UNKNOW_ERROT,
  36. "code_msg"=> $msg,
  37. "app_id"=> 'dw_box',
  38. "server_ip"=> getAwsSeverIp() ?: '127.0.0.1',
  39. "alerm_type"=> 'ERROR',
  40. "time"=> time()
  41. ];
  42. $appKey = 'a67362f15b13cf5df4ac695b39844c84';
  43. $tmpArr = $data;
  44. $tmpArr['app_key'] = $appKey;
  45. sort($tmpArr, SORT_STRING);
  46. $tmpStr = implode($tmpArr);
  47. $signStr = sha1($tmpStr);
  48. $data['sign'] = $signStr;
  49. $header = 'Host: amc-admin.duowan.com';
  50. $ret = (new dwHttp)->post($amc_url, $data, 5, $header);
  51. $ret = json_decode($ret, true);
  52. if ($ret['result']) {
  53. return true;
  54. } else {
  55. var_dump("【error】告警错误:" . $ret['msg']);
  56. return false;
  57. }
  58. }