Nessuna descrizione

manage_common.py 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # IRIS Source Code
  2. # Copyright (C) 2023 - DFIR-IRIS
  3. # contact@dfir-iris.org
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU Lesser General Public
  7. # License as published by the Free Software Foundation; either
  8. # version 3 of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # Lesser General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Lesser General Public License
  16. # along with this program; if not, write to the Free Software Foundation,
  17. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. from sqlalchemy import func
  19. from app import db
  20. from app.models.alerts import Severity
  21. def get_severities_list():
  22. """
  23. Get a list of severities from the database
  24. returns:
  25. list: A list of severities
  26. """
  27. return db.session.query(Severity).distinct().all()
  28. def get_severity_by_id(status_id: int) -> Severity:
  29. """
  30. Get a severity from the database by its ID
  31. args:
  32. status_id (int): The ID of the severity to retrieve
  33. returns:
  34. Severity: The severity object
  35. """
  36. return db.session.query(Severity).filter(Severity.severity_id == status_id).first()
  37. def search_severity_by_name(name: str, exact_match: bool = True) -> Severity:
  38. """
  39. Search for a severity by its name
  40. args:
  41. name (str): The name of the severity to search for
  42. exact_match (bool): Whether to search for an exact match or not
  43. returns:
  44. Severity: The severity object
  45. """
  46. if exact_match:
  47. return db.session.query(Severity).filter(func.lower(Severity.severity_name) == name.lower()).all()
  48. return db.session.query(Severity).filter(Severity.severity_name.ilike(f'%{name}%')).all()