Skip to content

Commit

Permalink
Merge pull request #80 from cykhoo0108/service-template
Browse files Browse the repository at this point in the history
Include service template to new service generation
  • Loading branch information
cykhoo0108 authored Apr 16, 2024
2 parents c4d5921 + 3993fe1 commit 0bab20d
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
77 changes: 77 additions & 0 deletions utils/services-template/Service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import boto3
import botocore
import requests

from utils.Config import Config
from services.Service import Service

###### TO DO #####
## Import required service module below
## Example
## from services.ec2.drivers.Ec2Instance import Ec2Instance


###### TO DO #####
## Replace ServiceName with
## getResources and advise method is default method that must have
## Feel free to develop method to support your checks
class ServiceName(Service):
def __init__(self, region):
super().__init__(region)
ssBoto = self.ssBoto

###### TO DO #####
## Initiate clients required for the check
## Example
## self.rdsClient = ssBoto.client('rds', config=self.bConfig)

return

## method to get resources for the services
## return the array of the resources
def getResources(self):
arr = {}

filters = []
if self.tags:
filters = self.tags

###### TO DO #####
## list the resources
## make sure filter by tagging is supported
## make sure pagination is supoprted
## Example
# results = self.ec2Client.describe_instances(
# Filters = filters
# )


# arr = results.get('Reservations')
# while results.get('NextToken') is not None:
# results = self.ec2Client.describe_instances(
# Filters = filters,
# NextToken = results.get('NextToken')
# )
# arr = arr + results.get('Reservations')

return arr


def advise(self):
objs = {}

###### TO DO #####
## call getResources method
## loop through the resources and run the checks in drivers
## Example
# instances = self.getResources()
# for instance in instances:
# instanceData = instance['Instances'][0]
# print('... (EC2) inspecting ' + instanceData['InstanceId'])
# obj = Ec2Instance(instanceData,self.ec2Client, self.cwClient)
# obj.run(self.__class__)

# objs[f"EC2::{instanceData['InstanceId']}"] = obj.getInfo()
#. del obj

return objs
33 changes: 33 additions & 0 deletions utils/services-template/drivers/ServiceDriver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import boto3
import botocore
import constants as _C

from services.Evaluator import Evaluator

###### TO DO #####
## Import modules that needed for this driver
## Example
## from services.ec2.drivers.Ec2SecGroup import Ec2SecGroup

###### TO DO #####
## Replace ServiceDriver with

class ServiceDriver(Evaluator):

###### TO DO #####
## Replace resource variable to meaningful name
## Modify based on your need
def __init__(self, resource):
super().__init__()
self.init()
return

###### TO DO #####
## Change the method name to meaningful name
## Check methods name must follow _check[Description]
def _checkDescription(self):
###### TO DO #####
## Develop the checks logic here
## If the resources failed the rules, flag the resource as example below
self.results['Rule Name'] = [-1, "Info for customer to identify the resource"]
return
16 changes: 16 additions & 0 deletions utils/services-template/service.reporter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"<CHECK_NAME>": {
"category": '<ENUM>', //REQUIRED, valid value (combination): O,S,R,P,C
"^description": '<string>', //REQUIRED
"shortDesc": '<string>', //OPTIONAL
"criticality": '<ENUM>', //REQUIRED, valid value (single): I, L, M, H
"downtime": '<int>', //OPTIONAL
"slowness": '<int>', //OPTIONAL
"additionalCost": '<int>', //OPTIONAL
"needFullTest": '<int>', //OPTIONAL
"ref": [ //OPTIONAL
"[<text_to_display>]<url>",
"[<text_to_display>]<url>",
],
}
}

0 comments on commit 0bab20d

Please sign in to comment.