Ei kuvausta

manage_alerts_status_routes.py 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. # IRIS Source Code
  2. # contact@dfir-iris.org
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Lesser General Public
  6. # License as published by the Free Software Foundation; either
  7. # version 3 of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # Lesser General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Lesser General Public License
  15. # along with this program; if not, write to the Free Software Foundation,
  16. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. from flask import Blueprint, Response, request
  18. from app.datamgmt.alerts.alerts_db import get_alert_status_list
  19. from app.datamgmt.alerts.alerts_db import get_alert_status_by_id
  20. from app.datamgmt.alerts.alerts_db import search_alert_status_by_name
  21. from app.datamgmt.alerts.alerts_db import get_alert_resolution_by_id
  22. from app.datamgmt.alerts.alerts_db import get_alert_resolution_list
  23. from app.datamgmt.alerts.alerts_db import search_alert_resolution_by_name
  24. from app.schema.marshables import AlertStatusSchema
  25. from app.schema.marshables import AlertResolutionSchema
  26. from app.blueprints.access_controls import ac_api_requires
  27. from app.blueprints.responses import response_error
  28. from app.blueprints.responses import response_success
  29. manage_alerts_status_rest_blueprint = Blueprint('manage_alerts_status_rest', __name__)
  30. @manage_alerts_status_rest_blueprint.route('/manage/alert-status/list', methods=['GET'])
  31. @ac_api_requires()
  32. def list_alert_status() -> Response:
  33. """
  34. Get the list of alert status
  35. Args:
  36. caseid (int): case id
  37. Returns:
  38. Flask Response object
  39. """
  40. l_cl = get_alert_status_list()
  41. schema = AlertStatusSchema()
  42. return response_success("", data=schema.dump(l_cl, many=True))
  43. @manage_alerts_status_rest_blueprint.route('/manage/alert-status/<int:classification_id>', methods=['GET'])
  44. @ac_api_requires()
  45. def get_case_alert_status(classification_id: int) -> Response:
  46. """
  47. Get the alert status
  48. Args:
  49. status_id (int): status id
  50. caseid (int): case id
  51. """
  52. cl = get_alert_status_by_id(classification_id)
  53. schema = AlertStatusSchema()
  54. return response_success("", data=schema.dump(cl))
  55. @manage_alerts_status_rest_blueprint.route('/manage/alert-status/search', methods=['POST'])
  56. @ac_api_requires()
  57. def search_alert_status():
  58. if not request.is_json:
  59. return response_error("Invalid request")
  60. alert_status = request.json.get('alert_status')
  61. if alert_status is None:
  62. return response_error("Invalid alert status. Got None")
  63. exact_match = request.json.get('exact_match', False)
  64. # Search for alerts status with a name that contains the specified search term
  65. alert_status = search_alert_status_by_name(alert_status, exact_match=exact_match)
  66. if not alert_status:
  67. return response_error("No alert status found")
  68. # Serialize the alert status and return them in a JSON response
  69. schema = AlertStatusSchema(many=True)
  70. return response_success("", data=schema.dump(alert_status))
  71. @manage_alerts_status_rest_blueprint.route('/manage/alert-resolutions/list', methods=['GET'])
  72. @ac_api_requires()
  73. def list_alert_resolution() -> Response:
  74. """
  75. Get the list of alert resolution
  76. Args:
  77. caseid (int): case id
  78. Returns:
  79. Flask Response object
  80. """
  81. l_cl = get_alert_resolution_list()
  82. schema = AlertResolutionSchema()
  83. return response_success("", data=schema.dump(l_cl, many=True))
  84. @manage_alerts_status_rest_blueprint.route('/manage/alert-resolutions/<int:resolution_id>', methods=['GET'])
  85. @ac_api_requires()
  86. def get_case_alert_resolution(resolution_id: int) -> Response:
  87. """
  88. Get the alert resolution
  89. Args:
  90. resolution_id (int): resolution id
  91. caseid (int): case id
  92. """
  93. cl = get_alert_resolution_by_id(resolution_id)
  94. schema = AlertResolutionSchema()
  95. return response_success("", data=schema.dump(cl))
  96. @manage_alerts_status_rest_blueprint.route('/manage/alert-resolutions/search', methods=['POST'])
  97. @ac_api_requires()
  98. def search_alert_resolution():
  99. if not request.is_json:
  100. return response_error("Invalid request")
  101. alert_resolution = request.json.get('alert_resolution_name')
  102. if alert_resolution is None:
  103. return response_error("Invalid alert resolution. Got None")
  104. exact_match = request.json.get('exact_match', False)
  105. # Search for alerts resolution with a name that contains the specified search term
  106. alert_res = search_alert_resolution_by_name(alert_resolution, exact_match=exact_match)
  107. if not alert_res:
  108. return response_error("No alert resolution found")
  109. # Serialize the alert_res and return them in a JSON response
  110. schema = AlertResolutionSchema(many=True)
  111. return response_success("", data=schema.dump(alert_res))