-
-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'amidaware:develop' into develop
- Loading branch information
Showing
35 changed files
with
506 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import django_filters | ||
from agents.models import Agent | ||
|
||
|
||
class AgentFilter(django_filters.FilterSet): | ||
last_seen_range = django_filters.DateTimeFromToRangeFilter(field_name="last_seen") | ||
total_ram_range = django_filters.NumericRangeFilter(field_name="total_ram") | ||
patches_last_installed_range = django_filters.DateTimeFromToRangeFilter( | ||
field_name="patches_last_installed" | ||
) | ||
|
||
client_id = django_filters.NumberFilter(method="client_id_filter") | ||
|
||
class Meta: | ||
model = Agent | ||
fields = [ | ||
"id", | ||
"hostname", | ||
"agent_id", | ||
"operating_system", | ||
"plat", | ||
"monitoring_type", | ||
"needs_reboot", | ||
"logged_in_username", | ||
"last_logged_in_user", | ||
"alert_template", | ||
"site", | ||
"policy", | ||
"last_seen_range", | ||
"total_ram_range", | ||
"patches_last_installed_range", | ||
] | ||
|
||
def client_id_filter(self, queryset, name, value): | ||
if value: | ||
return queryset.filter(site__client__id=value) | ||
return queryset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from rest_framework import viewsets | ||
from rest_framework.permissions import IsAuthenticated | ||
from django_filters.rest_framework import DjangoFilterBackend | ||
from rest_framework.filters import SearchFilter, OrderingFilter | ||
from rest_framework.request import Request | ||
from rest_framework.serializers import BaseSerializer | ||
|
||
from agents.models import Agent | ||
from agents.permissions import AgentPerms | ||
from beta.v1.agent.filter import AgentFilter | ||
from beta.v1.pagination import StandardResultsSetPagination | ||
from ..serializers import DetailAgentSerializer, ListAgentSerializer | ||
|
||
|
||
class AgentViewSet(viewsets.ModelViewSet): | ||
permission_classes = [IsAuthenticated, AgentPerms] | ||
queryset = Agent.objects.all() | ||
pagination_class = StandardResultsSetPagination | ||
http_method_names = ["get", "put"] | ||
filter_backends = [DjangoFilterBackend, SearchFilter, OrderingFilter] | ||
filterset_class = AgentFilter | ||
search_fields = ["hostname", "services"] | ||
ordering_fields = ["id"] | ||
ordering = ["id"] | ||
|
||
def check_permissions(self, request: Request) -> None: | ||
if "agent_id" in request.query_params: | ||
self.kwargs["agent_id"] = request.query_params["agent_id"] | ||
super().check_permissions(request) | ||
|
||
def get_permissions(self): | ||
if self.request.method == "POST": | ||
self.permission_classes = [IsAuthenticated] | ||
return super().get_permissions() | ||
|
||
def get_serializer_class(self) -> type[BaseSerializer]: | ||
if self.kwargs: | ||
if self.kwargs["pk"]: | ||
return DetailAgentSerializer | ||
return ListAgentSerializer |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from rest_framework import viewsets | ||
from rest_framework.permissions import IsAuthenticated | ||
|
||
from clients.models import Client | ||
from clients.permissions import ClientsPerms | ||
from ..serializers import ClientSerializer | ||
|
||
|
||
class ClientViewSet(viewsets.ModelViewSet): | ||
permission_classes = [IsAuthenticated, ClientsPerms] | ||
queryset = Client.objects.all() | ||
serializer_class = ClientSerializer | ||
http_method_names = ["get", "put"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from rest_framework.pagination import PageNumberPagination | ||
|
||
|
||
class StandardResultsSetPagination(PageNumberPagination): | ||
page_size = 100 | ||
page_size_query_param = "page_size" | ||
max_page_size = 1000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from rest_framework import serializers | ||
|
||
from agents.models import Agent | ||
from clients.models import Client, Site | ||
|
||
|
||
class ListAgentSerializer(serializers.ModelSerializer[Agent]): | ||
class Meta: | ||
model = Agent | ||
fields = "__all__" | ||
|
||
|
||
class DetailAgentSerializer(serializers.ModelSerializer[Agent]): | ||
status = serializers.ReadOnlyField() | ||
|
||
class Meta: | ||
model = Agent | ||
fields = ( | ||
"version", | ||
"operating_system", | ||
"plat", | ||
"goarch", | ||
"hostname", | ||
"agent_id", | ||
"last_seen", | ||
"services", | ||
"public_ip", | ||
"total_ram", | ||
"disks", | ||
"boot_time", | ||
"logged_in_username", | ||
"last_logged_in_user", | ||
"monitoring_type", | ||
"description", | ||
"mesh_node_id", | ||
"overdue_email_alert", | ||
"overdue_text_alert", | ||
"overdue_dashboard_alert", | ||
"offline_time", | ||
"overdue_time", | ||
"check_interval", | ||
"needs_reboot", | ||
"choco_installed", | ||
"wmi_detail", | ||
"patches_last_installed", | ||
"time_zone", | ||
"maintenance_mode", | ||
"block_policy_inheritance", | ||
"alert_template", | ||
"site", | ||
"policy", | ||
"status", | ||
"checks", | ||
"pending_actions_count", | ||
"cpu_model", | ||
"graphics", | ||
"local_ips", | ||
"make_model", | ||
"physical_disks", | ||
"serial_number", | ||
) | ||
|
||
|
||
class ClientSerializer(serializers.ModelSerializer[Client]): | ||
class Meta: | ||
model = Client | ||
fields = "__all__" | ||
|
||
|
||
class SiteSerializer(serializers.ModelSerializer[Site]): | ||
class Meta: | ||
model = Site | ||
fields = "__all__" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from rest_framework import viewsets | ||
from rest_framework.permissions import IsAuthenticated | ||
from django_filters.rest_framework import DjangoFilterBackend | ||
from rest_framework.filters import SearchFilter, OrderingFilter | ||
|
||
from clients.models import Site | ||
from clients.permissions import SitesPerms | ||
from beta.v1.pagination import StandardResultsSetPagination | ||
from ..serializers import SiteSerializer | ||
|
||
|
||
class SiteViewSet(viewsets.ModelViewSet): | ||
permission_classes = [IsAuthenticated, SitesPerms] | ||
queryset = Site.objects.all() | ||
serializer_class = SiteSerializer | ||
pagination_class = StandardResultsSetPagination | ||
http_method_names = ["get", "put"] | ||
filter_backends = [DjangoFilterBackend, SearchFilter, OrderingFilter] | ||
search_fields = ["name"] | ||
ordering_fields = ["id"] | ||
ordering = ["id"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from rest_framework import routers | ||
from .agent import views as agent | ||
from .client import views as client | ||
from .site import views as site | ||
|
||
router = routers.DefaultRouter() | ||
|
||
router.register("agent", agent.AgentViewSet, basename="agent") | ||
router.register("client", client.ClientViewSet, basename="client") | ||
router.register("site", site.SiteViewSet, basename="site") | ||
|
||
urlpatterns = router.urls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.