-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from cykhoo0108/service-template
Include service template to new service generation
- Loading branch information
Showing
3 changed files
with
126 additions
and
0 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
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 |
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,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 |
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,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>", | ||
], | ||
} | ||
} |