functions.py
1.14 KB
from .serializers import AgentCmdSerializer, AgentSurveySerializer
from majordome.models import AgentCmd, AgentSurvey
from datetime import datetime, timezone, timedelta
def get_list_agent_cmd(agent_name):
commands_sent_by_agent = AgentCmd.get_commands_sent_by_agent(agent_name)
commands_recivied_by_agent = AgentCmd.get_commands_sent_to_agent(agent_name)
number = 20
agent_cmds = commands_sent_by_agent | commands_recivied_by_agent
agents = AgentSurvey.objects.all()
agent_cmds = agent_cmds.exclude(sender="System", full_name="get_specific_cmds")
agent_cmds = agent_cmds.exclude(sender="System", full_name="get_all_cmds")
agent_cmds = agent_cmds.order_by("-s_deposit_time")
agent_cmds = agent_cmds[:number]
return AgentCmdSerializer(agent_cmds,many=True).data
def get_agent_survey_instance():
agents = AgentSurvey.objects.all()
datetime_now = datetime.utcnow()
date_minus_two_days = datetime_now - timedelta(days=2)
date_minus_two_days = date_minus_two_days.replace(tzinfo=timezone.utc)
agents = agents.exclude(updated__lt=date_minus_two_days)
return AgentSurveySerializer(agents,many=True).data