CloudMonitorController.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. using Newtonsoft.Json.Linq;
  2. using PMS.BusinessModels.Account;
  3. using PMS.BusinessModels.CloudMonitorManage;
  4. using PMS.BusinessModels.SMS;
  5. using PMS.BusinessModels.SysManager;
  6. using PMS.Interface;
  7. using PMS.Interface.CloudMonitorManage;
  8. using PMS.Interface.MessageManage;
  9. using PMS.Interface.SysManager;
  10. using PMS.Plugins.Common;
  11. using QWPlatform.SystemLibrary;
  12. using QWPlatform.SystemLibrary.Utils;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Configuration;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Threading;
  19. using System.Web;
  20. using System.Web.Mvc;
  21. namespace PMS.WebUI.Controllers
  22. {
  23. /// <summary>
  24. /// 云监控
  25. /// </summary>
  26. public class CloudMonitorController : BaseController
  27. {
  28. ICloudMonitor _cloudMonitor = InterfaceFactory.CreateBusinessInstance<ICloudMonitor>();
  29. //推送消息
  30. IMessageManage notice = InterfaceFactory.CreateBusinessInstance<IMessageManage>();
  31. /// <summary>
  32. /// 采集配置
  33. /// </summary>
  34. /// <returns></returns>
  35. public ActionResult CollectionConfigIndex()
  36. {
  37. var cloudMonitorConfig = _cloudMonitor.GetCloudMonitorConfig();
  38. var config = cloudMonitorConfig?.CollectionConfig;
  39. if (config == null) config = new CollectionConfig();
  40. ViewBag.CollectionConfig = config;
  41. return View();
  42. }
  43. /// <summary>
  44. /// 预警配置
  45. /// </summary>
  46. /// <returns></returns>
  47. public ActionResult EarlyWarningConfigIndex()
  48. {
  49. var cloudMonitorConfig = _cloudMonitor.GetCloudMonitorConfig();
  50. var config = cloudMonitorConfig?.AlertConfig;
  51. if (config == null) config = new AlertConfig();
  52. ViewBag.AlertConfig = config;
  53. return View();
  54. }
  55. /// <summary>
  56. /// 自定义预警配置
  57. /// </summary>
  58. /// <returns></returns>
  59. public ActionResult CustomAlertsConfigIndex()
  60. {
  61. return View();
  62. }
  63. /// <summary>
  64. /// 自定义预警编辑界面
  65. /// </summary>
  66. /// <returns></returns>
  67. public ActionResult EditCustomAlertsConfig()
  68. {
  69. return View();
  70. }
  71. /// <summary>
  72. /// API预警配置
  73. /// </summary>
  74. /// <returns></returns>
  75. public ActionResult APIAlertsConfigIndex()
  76. {
  77. return View();
  78. }
  79. /// <summary>
  80. /// API预警编辑界面
  81. /// </summary>
  82. /// <returns></returns>
  83. public ActionResult EditAPIAlertsConfig()
  84. {
  85. return View();
  86. }
  87. /// <summary>
  88. /// 服务器硬件监控
  89. /// </summary>
  90. /// <returns></returns>
  91. public ActionResult ServerHardwareMonitoringIndex()
  92. {
  93. return View();
  94. }
  95. /// <summary>
  96. /// 预警管理
  97. /// </summary>
  98. /// <returns></returns>
  99. public ActionResult EarlyWarningManagementIndex()
  100. {
  101. return View();
  102. }
  103. /// <summary>
  104. /// 未处理预警处理
  105. /// </summary>
  106. /// <returns></returns>
  107. public ActionResult UnprocessedEarlyWarningManagementIndex()
  108. {
  109. var cloudMonitorConfig = _cloudMonitor.GetCloudMonitorConfig();
  110. var config = cloudMonitorConfig?.AlertConfig;
  111. if (config == null) config = new AlertConfig();
  112. ViewBag.Model = config;
  113. return View();
  114. }
  115. /// <summary>
  116. /// 预警详情
  117. /// </summary>
  118. /// <returns></returns>
  119. [CheckLogin(false)]
  120. public ActionResult EarlyWarningInfo(string id)
  121. {
  122. ViewBag.Model = _cloudMonitor.GetServerAlertByAlertlId(id);
  123. return View();
  124. }
  125. /// <summary>
  126. /// 预警处理
  127. /// </summary>
  128. /// <returns></returns>
  129. public ActionResult WarningProcessing()
  130. {
  131. var data = GetCurrentUser();
  132. ViewBag.UserName = data.Name;
  133. return View();
  134. }
  135. /// <summary>
  136. /// 批量预警处理
  137. /// </summary>
  138. /// <returns></returns>
  139. public ActionResult BatchWarningProcessing()
  140. {
  141. var data = GetCurrentUser();
  142. ViewBag.UserName = data.Name;
  143. return View();
  144. }
  145. /// <summary>
  146. /// 项目监控管理
  147. /// </summary>
  148. /// <returns></returns>
  149. public ActionResult ProjectMonitoringManagementIndex()
  150. {
  151. return View();
  152. }
  153. /// <summary>
  154. /// 服务器信息
  155. /// </summary>
  156. /// <returns></returns>
  157. public ActionResult ServerInfo()
  158. {
  159. return View();
  160. }
  161. /// <summary>
  162. /// 上传指标记录
  163. /// </summary>
  164. /// <returns></returns>
  165. public ActionResult UploadIndicatorRecordIndex()
  166. {
  167. return View();
  168. }
  169. /// <summary>
  170. /// 保存采集配置
  171. /// </summary>
  172. /// <param name="config"></param>
  173. /// <returns></returns>
  174. public ActionResult SaveCollectionConfig(CollectionConfig config)
  175. {
  176. return Content(_cloudMonitor.SaveCollectionConfig(config) ? "1" : "0", "text/plain");
  177. }
  178. /// <summary>
  179. /// 保存预警配置
  180. /// </summary>
  181. /// <param name="config"></param>
  182. /// <returns></returns>
  183. public ActionResult SaveAlertConfig(AlertConfig config)
  184. {
  185. return Content(_cloudMonitor.SaveAlertConfig(config) ? "1" : "0", "text/plain");
  186. }
  187. /// <summary>
  188. /// 获取预警配置
  189. /// </summary>
  190. /// <returns></returns>
  191. public ActionResult GetAlertConfiguration()
  192. {
  193. var cloudMonitorConfig = _cloudMonitor.GetCloudMonitorConfig();
  194. var config = cloudMonitorConfig?.AlertConfig;
  195. if (config == null) config = new AlertConfig();
  196. return Content(Strings.ObjectToJson(config), "application/json");
  197. }
  198. /// <summary>
  199. /// 获取自定义配置
  200. /// </summary>
  201. /// <returns></returns>
  202. public ActionResult GetCustomAlertModel(string search)
  203. {
  204. var data = _cloudMonitor.GetCustomAlertModelByChannelId(GetAuthDats()?.Channel, search);
  205. return Content(Strings.ObjectToJson(data), "application/json");
  206. }
  207. /// <summary>
  208. /// 获取自定义API配置
  209. /// </summary>
  210. /// <returns></returns>
  211. public ActionResult GetCustomAPIModel(string search)
  212. {
  213. var data = _cloudMonitor.GetCustomAPIModelByChannelId(GetAuthDats()?.Channel, search);
  214. return Content(Strings.ObjectToJson(data), "application/json");
  215. }
  216. /// <summary>
  217. /// 根据项目id获取 启动的自定义预警配置
  218. /// </summary>
  219. /// <param name="itemId"></param>
  220. /// <returns></returns>
  221. public ActionResult GetCustomAlertModelByItemIdAndStart(string itemid)
  222. {
  223. var data = _cloudMonitor.GetCustomAlertModelByItemIdAndStart(itemid);
  224. return Content(Strings.ObjectToJson(data), "application/json");
  225. }
  226. /// <summary>
  227. /// 新增自定义配置
  228. /// </summary>
  229. /// <param name="model"></param>
  230. /// <returns></returns>
  231. public ActionResult SaveCustomAlert(CustomAlertModel model)
  232. {
  233. var data = false;
  234. if (string.IsNullOrEmpty(model.ID))
  235. {
  236. model.ID = Guid.NewGuid().ToString("N");
  237. model.创建人ID = GetCurrentUser().ID;
  238. data = _cloudMonitor.InsertCustomAlert(model);
  239. }
  240. else
  241. {
  242. data = _cloudMonitor.UpdateCustomAlert(model);
  243. }
  244. return Content(data ? "1" : "0", "text/plain");
  245. }
  246. /// <summary>
  247. /// 新增自定义API配置
  248. /// </summary>
  249. /// <param name="model"></param>
  250. /// <returns></returns>
  251. public ActionResult SaveCustomAPI(CustomAPIModel model)
  252. {
  253. var data = false;
  254. if (string.IsNullOrEmpty(model.ID))
  255. {
  256. model.ID = Guid.NewGuid().ToString("N");
  257. model.创建人ID = GetCurrentUser().ID;
  258. data = _cloudMonitor.InsertCustomAPI(model);
  259. }
  260. else
  261. {
  262. data = _cloudMonitor.UpdateCustomAPI(model);
  263. }
  264. return Content(data ? "1" : "0", "text/plain");
  265. }
  266. /// <summary>
  267. /// 根据项目id获取服务器信息
  268. /// </summary>
  269. /// <param name="itemid"></param>
  270. /// <returns></returns>
  271. public ActionResult GetServerByItemId(string itemid)
  272. {
  273. var data = _cloudMonitor.GetServerByItemId(itemid);
  274. return Content(Strings.ObjectToJson(data), "application/json");
  275. }
  276. /// <summary>
  277. /// 根据id删除
  278. /// </summary>
  279. /// <param name="id"></param>
  280. /// <returns></returns>
  281. public ActionResult DeleteCustomAlertById(string id)
  282. {
  283. var data = _cloudMonitor.DeleteCustomAlertById(id);
  284. return Content(data ? "1" : "0", "text/plain");
  285. }
  286. /// <summary>
  287. /// 根据id删除
  288. /// </summary>
  289. /// <param name="id"></param>
  290. /// <returns></returns>
  291. public ActionResult DeleteCustomAPIById(string id)
  292. {
  293. var data = _cloudMonitor.DeleteCustomAPIById(id);
  294. return Content(data ? "1" : "0", "text/plain");
  295. }
  296. /// <summary>
  297. /// 获取采集配置
  298. /// </summary>
  299. /// <returns></returns>
  300. public ActionResult GetCollectionConfig()
  301. {
  302. var cloudMonitorConfig = _cloudMonitor.GetCloudMonitorConfig();
  303. var config = cloudMonitorConfig?.CollectionConfig;
  304. return Content(Strings.ObjectToJson(config), "application/json");
  305. }
  306. /// <summary>
  307. /// 获取所有服务器信息
  308. /// </summary>
  309. /// <returns></returns>
  310. public ActionResult GetServerInfoAll(string search)
  311. {
  312. var data = _cloudMonitor.GetServerIndexInfoByChannelId(GetAuthDats().Channel, search);
  313. return Content(Strings.ObjectToJson(data), "application/json");
  314. }
  315. /// <summary>
  316. /// 获取所有服务器信息 通过项目id过滤
  317. /// </summary>
  318. /// <returns></returns>
  319. public ActionResult GetServerInfoByProjectId(string projectId)
  320. {
  321. var data = new List<ServerIndexInfoModel>();
  322. if (!string.IsNullOrEmpty(projectId))
  323. {
  324. var projectArr = projectId.Split(',');
  325. var authProjectArr = GetAuthDats().Project.Split(',');
  326. //传入的渠道id和自身有的权限的渠道id 取交集
  327. var intersection = projectArr.Intersect(authProjectArr);
  328. if (intersection.Any())
  329. data = _cloudMonitor.GetServerIndexInfoByProjectId(string.Join(",", intersection));
  330. }
  331. return Content(Strings.ObjectToJson(data), "application/json");
  332. }
  333. /// <summary>
  334. /// 获取所有服务器信息 通过渠道id过滤
  335. /// </summary>
  336. /// <returns></returns>
  337. public ActionResult GetServerInfoByChannelId(string channelId)
  338. {
  339. var data = new List<ServerIndexInfoModel>();
  340. if (!string.IsNullOrEmpty(channelId))
  341. {
  342. var channelArr = channelId.Split(',');
  343. var authChannelArr = GetAuthDats().Channel.Split(',');
  344. //传入的渠道id和自身有的权限的渠道id 取交集
  345. var intersection = channelArr.Intersect(authChannelArr);
  346. if (intersection.Any())
  347. data = _cloudMonitor.GetServerIndexInfoByChannelId(string.Join(",", intersection));
  348. }
  349. return Content(Strings.ObjectToJson(data), "application/json");
  350. }
  351. /// <summary>
  352. /// 获取指标详情 根据指标id
  353. /// </summary>
  354. /// <param name="indexId"></param>
  355. public ActionResult GetServerDetailByIndexId(string indexId, DateTime startTime, DateTime endTime)
  356. {
  357. var data = _cloudMonitor.GetServerIndexDetailByIndexId(indexId, startTime, endTime);
  358. return Content(Strings.ObjectToJson(data), "application/json");
  359. }
  360. /// <summary>
  361. /// 获取指标详情 根据服务器id
  362. /// </summary>
  363. /// <param name="indexId"></param>
  364. public ActionResult GetServerDetailByServerId(string serverId, DateTime startTime, DateTime endTime)
  365. {
  366. var data = _cloudMonitor.GetServerIndexDetailByServerId(serverId, startTime, endTime);
  367. return Content(Strings.ObjectToJson(data), "application/json");
  368. }
  369. /// <summary>
  370. /// 获取所有服务器预警
  371. /// </summary>
  372. /// <returns></returns>
  373. public ActionResult GetServerAlertAll(string search)
  374. {
  375. var data = _cloudMonitor.GetServerAlertAll(search);
  376. return Content(Strings.ObjectToJson(data), "application/json");
  377. }
  378. /// <summary>
  379. /// 根据条件获取服务器预警
  380. /// </summary>
  381. /// <returns></returns>
  382. [HttpPost]
  383. public ActionResult GetServerAlertBySearch(ServerAlertSearch search)
  384. {
  385. if (string.IsNullOrEmpty(search.QDID))
  386. {
  387. search.QDID = GetAuthDats().Channel;
  388. }
  389. var data = _cloudMonitor.GetServerAlertBySearch(search);
  390. return Content(Strings.ObjectToJson(data), "application/json");
  391. }
  392. /// <summary>
  393. /// 插入服务器预警处理
  394. /// </summary>
  395. /// <param name="model"></param>
  396. /// <returns></returns>
  397. public ActionResult InsertServerAlertProcess(ServerAlertProcessModel model)
  398. {
  399. var data = _cloudMonitor.InsertServerAlertProcess(model);
  400. return Content(data ? "1" : "0", "text/plain");
  401. }
  402. /// <summary>
  403. /// 查询服务器预警处理过程
  404. /// </summary>
  405. /// <param name="alertId"></param>
  406. /// <returns></returns>
  407. public ActionResult GetServerAlertProcessByAlertId(string alertId)
  408. {
  409. var data = _cloudMonitor.GetServerAlertProcessByAlertId(alertId);
  410. return Content(Strings.ObjectToJson(data), "application/json");
  411. }
  412. /// <summary>
  413. /// 获取全部项目监控数据
  414. /// </summary>
  415. /// <returns></returns>
  416. public ActionResult GetProjectMonitorAll()
  417. {
  418. var data = _cloudMonitor.GetProjectMonitorAll();
  419. return Content(Strings.ObjectToJson(data), "application/json");
  420. }
  421. /// <summary>
  422. /// 根据查询获取全部项目监控
  423. /// </summary>
  424. /// <returns></returns>
  425. [HttpPost]
  426. public ActionResult GetProjectMonitorBySearch(ServerAlertSearch search)
  427. {
  428. if (string.IsNullOrEmpty(search.QDID))
  429. {
  430. search.QDID = GetAuthDats().Channel;
  431. }
  432. var data = _cloudMonitor.GetProjectMonitorBySearch(search);
  433. return Content(Strings.ObjectToJson(data), "application/json");
  434. }
  435. /// <summary>
  436. /// 停止项目监控
  437. /// </summary>
  438. /// <param name="projectId"></param>
  439. public ActionResult StopProjectMonitor(string projectId)
  440. {
  441. var data = _cloudMonitor.StartOrStopProjectMonitor(projectId, false);
  442. return Content(data ? "1" : "0", "text/plain");
  443. }
  444. /// <summary>
  445. /// 插入数据库数据
  446. /// </summary>
  447. /// <param name="model"></param>
  448. /// <returns></returns>
  449. public ActionResult InsertDbInfo(DbInfoModel model)
  450. {
  451. var data = _cloudMonitor.InsertDbInfo(model);
  452. return Content(data ? "1" : "0", "text/plain");
  453. }
  454. /// <summary>
  455. /// 修改数据库数据
  456. /// </summary>
  457. /// <param name="model"></param>
  458. /// <returns></returns>
  459. public ActionResult UpdateDbInfo(DbInfoModel model)
  460. {
  461. var data = _cloudMonitor.UpdateDbInfo(model);
  462. return Content(data ? "1" : "0", "text/plain");
  463. }
  464. /// <summary>
  465. /// 获取数据库数据,根据服务器ID过滤
  466. /// </summary>
  467. /// <param name="channelId"></param>
  468. /// <returns></returns>
  469. public ActionResult GetDbInfoByServerId(string serverId)
  470. {
  471. var data = _cloudMonitor.GetDbInfoByServerId(serverId);
  472. return Content(Strings.ObjectToJson(data), "application/json");
  473. }
  474. /// <summary>
  475. /// 获取数据库数据,根据ID过滤
  476. /// </summary>
  477. /// <param name="channelId"></param>
  478. /// <returns></returns>
  479. public ActionResult GetDbInfoById(string id)
  480. {
  481. var data = _cloudMonitor.GetDbInfoById(id);
  482. return Content(Strings.ObjectToJson(data), "application/json");
  483. }
  484. /// <summary>
  485. /// 删除数据库数据,根据ID
  486. /// </summary>
  487. /// <param name="id"></param>
  488. /// <returns></returns>
  489. public ActionResult DeleteDbInfoById(string id)
  490. {
  491. var data = _cloudMonitor.DeleteDbInfoById(id);
  492. return Content(data ? "1" : "0", "text/plain");
  493. }
  494. /// <summary>
  495. /// 查询上传指标数据
  496. /// </summary>
  497. /// <returns></returns>
  498. [HttpPost]
  499. public ActionResult GetPushIndexData(IndexSearch search)
  500. {
  501. if (string.IsNullOrEmpty(search.QDID))
  502. {
  503. search.QDID = GetAuthDats().Channel;
  504. }
  505. var data = _cloudMonitor.GetPushIndexData(search);
  506. return Content(Strings.ObjectToJson(data), "application/json");
  507. }
  508. }
  509. /// <summary>
  510. /// 云监控对外部开放的接口
  511. /// </summary>
  512. [Encryption()]
  513. public class CloudMonitorExternalController : BaseController
  514. {
  515. ICloudMonitor _cloudMonitor = InterfaceFactory.CreateBusinessInstance<ICloudMonitor>();
  516. //推送消息
  517. IMessageManage notice = InterfaceFactory.CreateBusinessInstance<IMessageManage>();
  518. public static string IsCollection = ConfigurationManager.AppSettings["IsCollection"].ToStringEx();
  519. //执行登录
  520. [HttpPost]
  521. [CheckLogin(false)]
  522. public ActionResult CheckLogin(DecryInput<LoginInput> input)
  523. {
  524. string account = input.Value.account;
  525. string pwd = input.Value.pwd;
  526. string vcode = input.Value.vcode;
  527. var code = this.Session["vcode"];
  528. var json = new PmsJsonResoult(System.Net.HttpStatusCode.OK, "登录成功", null);
  529. if (code == null || code.ToString().ToLower() != vcode.ToLower())
  530. {//验证码不正确
  531. json.msg = "验证码不正确,请重新录入";
  532. json.code = System.Net.HttpStatusCode.PreconditionFailed;
  533. return Content(json.ToString(), "application/json");
  534. }
  535. //清空验证码
  536. this.Session["vcode"] = null;
  537. //读取IP
  538. var ip = QWPlatform.SystemLibrary.Utils.Strings.GetWebClientIP();
  539. //到数据库中验证是否正确
  540. var r = account_obj.Login(account, pwd, ip);
  541. if (r.Success)
  542. {//登录成功
  543. return Content(new PmsJsonResoult(System.Net.HttpStatusCode.OK, r.Message, null).ToString(), "application/json");
  544. }
  545. else
  546. {//登录失败
  547. return Content(new PmsJsonResoult(System.Net.HttpStatusCode.Forbidden, r.Message, null).ToString(), "application/json");
  548. }
  549. }
  550. /// <summary>
  551. /// 获取用户信息
  552. /// </summary>
  553. /// <returns></returns>
  554. public ActionResult GetUserInfo()
  555. {
  556. var data = GetCurrentUser();
  557. var userInfo = new UserInfo();
  558. userInfo.ID = data.ID;
  559. userInfo.Account = data.Account;
  560. userInfo.Name = data.Name;
  561. userInfo.Email = data.Email;
  562. userInfo.Company = data.Company;
  563. userInfo.CompanyID = data.CompanyID;
  564. userInfo.PersonJob = data.PersonJob;
  565. return Content(Strings.ObjectToJson(userInfo), "application/json");
  566. }
  567. /// <summary>
  568. /// 获取项目监控状态
  569. /// </summary>
  570. /// <returns></returns>
  571. public ActionResult GetItemList()
  572. {
  573. var data = _cloudMonitor.GetProjectMonitorByChannelId(GetAuthDats().Channel);
  574. return Content(Strings.ObjectToJson(data), "application/json");
  575. }
  576. /// <summary>
  577. /// 根据项目id获取服务器信息
  578. /// </summary>
  579. /// <param name="itemid"></param>
  580. /// <returns></returns>
  581. public ActionResult GetServerByItemId(string itemid)
  582. {
  583. var data = _cloudMonitor.GetServerByItemId(itemid);
  584. return Content(Strings.ObjectToJson(data), "application/json");
  585. }
  586. /// <summary>
  587. /// 获取采集配置
  588. /// </summary>
  589. /// <returns></returns>
  590. public ActionResult GetCollectionConfig()
  591. {
  592. var cloudMonitorConfig = _cloudMonitor.GetCloudMonitorConfig();
  593. var config = cloudMonitorConfig?.CollectionConfig;
  594. return Content(Strings.ObjectToJson(config), "application/json");
  595. }
  596. /// <summary>
  597. /// 根据项目id获取 启动的自定义预警配置
  598. /// </summary>
  599. /// <param name="itemId"></param>
  600. /// <returns></returns>
  601. public ActionResult GetCustomAlertModelByItemIdAndStart(string itemid)
  602. {
  603. var data = _cloudMonitor.GetCustomAlertModelByItemIdAndStart(itemid);
  604. return Content(Strings.ObjectToJson(data), "application/json");
  605. }
  606. /// <summary>
  607. /// 根据项目id获取 启动的API预警配置
  608. /// </summary>
  609. /// <param name="itemId"></param>
  610. /// <returns></returns>
  611. public ActionResult GetCustomServerModelByItemIdAndStart(string itemid)
  612. {
  613. var data = _cloudMonitor.GetCustomServerModelByItemIdAndStart(itemid);
  614. return Content(Strings.ObjectToJson(data), "application/json");
  615. }
  616. /// <summary>
  617. /// 启动或者停止项目监控
  618. /// </summary>
  619. /// <param name="projectId"></param>
  620. public ActionResult StartOrStopProjectMonitor(string projectId, bool state, string clientId)
  621. {
  622. var data = _cloudMonitor.StartOrStopProjectMonitor(projectId, state, clientId);
  623. return Content(data ? "1" : "0", "text/plain");
  624. }
  625. #region 接收处理上报数据
  626. /// <summary>
  627. /// 接收上报的服务器信息
  628. /// </summary>
  629. /// <param name="serverInfos"></param>
  630. /// <returns></returns>
  631. [CheckLogin(false)]
  632. public ActionResult ReceiveServerInfo(string clientId, DecryInput<List<Ret<ServerInfo>>> input)
  633. {
  634. if(IsCollection=="0")
  635. {
  636. return Content("1");
  637. }
  638. List<Ret<ServerInfo>> serverInfos = input.Value;
  639. _cloudMonitor.ReceiveServerInfo(clientId, serverInfos);
  640. return Content("1");
  641. }
  642. /// <summary>
  643. /// 接收上报的数据库连接数信息
  644. /// </summary>
  645. /// <param name="dbConnectInfos"></param>
  646. /// <returns></returns>
  647. [CheckLogin(false)]
  648. public ActionResult ReceiveDbConnectInfo(string clientId, DecryInput<List<Ret<DbConnectInfo>>> input)
  649. {
  650. if (IsCollection == "0")
  651. {
  652. return Content("1");
  653. }
  654. List<Ret<DbConnectInfo>> dbConnectInfos = input.Value;
  655. _cloudMonitor.ReceiveDbConnectInfo(clientId, dbConnectInfos);
  656. return Content("1");
  657. }
  658. /// <summary>
  659. /// 接收上报的数据库死锁信息
  660. /// </summary>
  661. /// <param name="dbLockedInfos"></param>
  662. /// <returns></returns>
  663. [CheckLogin(false)]
  664. public ActionResult ReceiveDbLockedInfo(string clientId, DecryInput<List<Ret<DbLockedInfo>>> input)
  665. {
  666. if (IsCollection == "0")
  667. {
  668. return Content("1");
  669. }
  670. List<Ret<DbLockedInfo>> dbLockedInfos = input.Value;
  671. _cloudMonitor.ReceiveDbLockedInfo(clientId, dbLockedInfos);
  672. return Content("1");
  673. }
  674. /// <summary>
  675. /// 接收上报的服务发现信息
  676. /// </summary>
  677. /// <returns></returns>
  678. [CheckLogin(false)]
  679. public ActionResult ReceiveServiceWorkStateInfo(string clientId, DecryInput<List<Ret<ServiceWorkStateInfo>>> input)
  680. {
  681. if (IsCollection == "0")
  682. {
  683. return Content("1");
  684. }
  685. List<Ret<ServiceWorkStateInfo>> serviceWorkStateInfos = input.Value;
  686. _cloudMonitor.ReceiveServiceWorkStateInfo(clientId, serviceWorkStateInfos);
  687. return Content("1");
  688. }
  689. /// <summary>
  690. /// 接收上报的自定义预警信息
  691. /// </summary>
  692. /// <returns></returns>
  693. [CheckLogin(false)]
  694. public ActionResult ReceiveDbCustomAlertInfo(string clientId, DecryInput<Ret<DbCustomAlertInfo>> input)
  695. {
  696. if (IsCollection == "0")
  697. {
  698. return Content("1");
  699. }
  700. Ret<DbCustomAlertInfo> info = input.Value;
  701. _cloudMonitor.ReceiveDbCustomAlertInfo(clientId, info);
  702. return Content("1");
  703. }
  704. /// <summary>
  705. /// 接收上报的自定义服务信息
  706. /// </summary>
  707. /// <returns></returns>
  708. [CheckLogin(false)]
  709. public ActionResult ReceiveCustomServiceInfo(string clientId, DecryInput<Ret<CustomServiceInfo>> input)
  710. {
  711. if (IsCollection == "0")
  712. {
  713. return Content("1");
  714. }
  715. Ret<CustomServiceInfo> info = input.Value;
  716. _cloudMonitor.ReceiveCustomServiceInfo(clientId, info);
  717. return Content("1");
  718. }
  719. #endregion
  720. }
  721. }