-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the monitoring system to azure
- Loading branch information
Showing
7 changed files
with
122 additions
and
14 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
15 changes: 15 additions & 0 deletions
15
...governance/cloud_resource_orchestration/clouds/azure/resource_groups/abstract_resource.py
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,15 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
from cloud_governance.common.clouds.azure.compute.compute_operations import ComputeOperations | ||
from cloud_governance.common.clouds.azure.compute.resource_group_operations import ResourceGroupOperations | ||
|
||
|
||
class AbstractResource(ABC): | ||
|
||
def __init__(self): | ||
self._resource_group_operations = ResourceGroupOperations() | ||
self._compute_client = ComputeOperations() | ||
|
||
@abstractmethod | ||
def run(self): | ||
pass |
54 changes: 54 additions & 0 deletions
54
...rnance/cloud_resource_orchestration/clouds/azure/resource_groups/monitor_cro_resources.py
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,54 @@ | ||
from azure.mgmt.compute.v2023_03_01.models import VirtualMachine | ||
|
||
from cloud_governance.cloud_resource_orchestration.clouds.azure.resource_groups.abstract_resource import \ | ||
AbstractResource | ||
from cloud_governance.cloud_resource_orchestration.utils.constant_variables import DURATION, TICKET_ID | ||
|
||
|
||
class MonitorCROResources(AbstractResource): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
def __monitor_instances(self): | ||
""" | ||
This method the resources and return the data | ||
:return: | ||
:rtype: | ||
""" | ||
monitored_ticket_ids = {} | ||
virtual_machines: [VirtualMachine] = self._compute_client.get_all_instances() | ||
for virtual_machine in virtual_machines: | ||
name, tags = virtual_machine.name, virtual_machine.tags | ||
found_duration = self._compute_client.check_tag_name(tags=tags, tag_name=DURATION) | ||
print(virtual_machine.priority) | ||
if found_duration: | ||
ticket_id = self._compute_client.check_tag_name(tags=tags, tag_name=TICKET_ID) | ||
monitored_ticket_ids.setdefault(ticket_id, []).append({ | ||
'region_name': virtual_machine.location, | ||
'ticket_id': ticket_id, | ||
'instance_id': virtual_machine.vm_id, | ||
'instance_create_time': virtual_machine.time_created, | ||
'instance_state': 'NA', # virtual_machine.instance_view - not available | ||
'instance_type': virtual_machine.hardware_profile.vm_size, | ||
'instance_running_days': 0, | ||
'instance_plan': virtual_machine.priority, | ||
'user_cro': self._compute_client.check_tag_name(tags=tags, tag_name='UserCRO'), | ||
'user': self._compute_client.check_tag_name(tags=tags, tag_name='User'), | ||
'manager': self._compute_client.check_tag_name(tags=tags, tag_name='Manager'), | ||
'approved_manager': self._compute_client.check_tag_name(tags=tags, tag_name='ApprovedManager'), | ||
'owner': self._compute_client.check_tag_name(tags=tags, tag_name='Owner'), | ||
'project': self._compute_client.check_tag_name(tags=tags, tag_name='Project'), | ||
'instance_name': virtual_machine.name, | ||
'email': self._compute_client.check_tag_name(tags=tags, tag_name='Email'), | ||
'duration': found_duration, | ||
'estimated_cost': self._compute_client.check_tag_name(tags=tags, tag_name='EstimatedCost') | ||
}) | ||
return monitored_ticket_ids | ||
|
||
def run(self): | ||
""" | ||
This method start Azure CRO monitor | ||
:return: | ||
""" | ||
return self.__monitor_instances() |
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