Skip to content

Commit

Permalink
Added Alarm Checker Support For Azure (#6)
Browse files Browse the repository at this point in the history
Added Alarm Checker Support For Azure and PD integration Check
  • Loading branch information
anshit-sre-sre authored Oct 13, 2023
1 parent 0b47e26 commit 3684910
Show file tree
Hide file tree
Showing 27 changed files with 1,267 additions and 225 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM python:3.8-slim

COPY requirements.txt /requirements.txt
RUN pip3 install -r /requirements.txt

RUN mkdir - /root/.aws
RUN curl -L https://aka.ms/InstallAzureCLIDeb | bash
COPY src /src
COPY inputs /inputs
COPY inputs /inputs
2 changes: 1 addition & 1 deletion deployments/prod/kubernetes/aws/cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#
# 2. In CronJob kind
# a. Update the medadata name
# b. Update teh namespace
# b. Update the namespace
# c. Update the schedule for cron
# d. Update the Container name
# e. Update the dcker repo path if required
Expand Down
43 changes: 15 additions & 28 deletions inputs/aws/aws_input.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,29 @@
spec:
cloud: aws
env: prod
regions: ['us-east-1', 'ap-south-1' , 'eu-central-1', 'us-east-2']
exclude_resources_on_tags:
tag: 'Monitor'
value: 'False'
env_region_map:
dc01:
region: ''
secret_name: 'infinity-prod-user'
secretRegion: ''
#aws_access_key: ''
#aws_access_secret: ''

pagerduty:
pd_apikey_secret_name: ''
pd_apikey_secret_region: ''
pd_integration_key_check: True

resources_to_ckeck: [TargetGroupAWSResource, SQSQueueAWSResourceGroup, LoadBalancerAWSResource, ElasticacheRedisAWSResource ]

awsAccessSecrets:
useAwsSecretManager: True
secretName: 'infinity-prod-user'
secretRegion: 'ap-southeast-1'
#useAwsSecretManager: False
#aws_access_key: ''
#aws_access_secret: ''

outboundNotification:
slack:
useSlack: True
slackChannelName: 'infinity-bot'
useAwsSecretManager: True
secretName: 'infinity-slack-secrets'
secretRegion: 'ap-southeast-1'
#useAwsSecretManager: False
#slackWebhookUrl: ''

sheets:
googleSheets:
useSheets: True
useAwsSecretManager: True
secretName: 'gsheets_service_account_credentials'
secretRegion: 'ap-southeast-1'
secretRegion: ''
#useAwsSecretManager: False
#credentialsInfo:
#type: 'service_account'
Expand All @@ -50,10 +42,5 @@ spec:
#auth_provider_x509_cert_url: ''
#client_x509_cert_url: ''
sharing:
reader: 'moengage.com'
writer: '[email protected]'

buisness_team_map:
consul:
useConsul: True
url: 'https://consul.moengage.com'
reader: ''
writer: ''
34 changes: 34 additions & 0 deletions inputs/azure/azure_input.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
######## Azure Cloud Related Inputs ########

spec:
cloud: azure
env: prod
env_region_map:
dc01:
region: ''
subscription_id: ''
client_id: ''
client_secret: ''
tenant_id: ''
resource_group: ''

sheets:
googleSheets:
useSheets: True
useAwsSecretManager: True
secretName: 'gsheets_service_account_credentials'
secretRegion: ''
#useAwsSecretManager: False
#credentialsInfo:
#type: 'service_account'
#project_id: ''
#private_key_id: ''
#client_email: ''
#client_id: ''
#auth_uri: ''
#token_uri: ''
#auth_provider_x509_cert_url: ''
#client_x509_cert_url: ''
sharing:
reader: ''
writer: ''
9 changes: 9 additions & 0 deletions inputs/notification.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
outboundNotification:
slack:
useSlack: True
slackChannelName: []
useAwsSecretManager: True
secretName: 'infinity-slack-secrets'
secretRegion: ''
#useAwsSecretManager: False
#slackWebhookUrl: []
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ sentry-sdk==1.0.0
requests==2.25.1
click==8.0.1
pyyaml
ndg-httpsclient
pyopenssl
pyasn1
105 changes: 64 additions & 41 deletions src/alarm_checker.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,78 @@
from outputs.sheets import *

from cloud.aws.aws_main import aws_alarm_checker
from cloud.azure.azure_main import azure_alarm_checker

@click.command()
@click.option("--input", required=True, help="Input Yaml file - <path of yaml file>")
def main(input):
@click.option("--inputs", required=True, help="Comma Separated Input Yaml file for each cloud - <path of yaml file>")
def main(inputs):

'''
Main Function to check for all unmonitored resources present in AWS.
This will store all those resources in spreadsheet and send the sheet url to slack channel
'''

set_input(input)

# This will read all the inputs provided in input_yaml
yaml_inputs = yaml_reader()
print(input)

# Fetching the environment
env = yaml_inputs['env']

# Fetching list of regions based on the environment selected.
regions = yaml_inputs['regions']

cloud = yaml_inputs['cloud']

# Creating spreadsheets
spreadsheet_writer = create_sheets(cloud, env, yaml_inputs)

# Geting buisness team map from consul host
business_team_map = get_business_team_map(yaml_inputs['buisness_team_map'])

if cloud == 'aws':
has_unmonitored_resources = aws_alarm_checker( env, yaml_inputs, business_team_map, regions, spreadsheet_writer)

else:
raise Exception("Please add the code for %s", cloud )

if has_unmonitored_resources:

# After Filling the spreadsheet with all the information, it is resized and pruned and
# then its link is sent to the required slack channel

spreadsheet_writer.autoresize_spreadsheet()
spreadsheet_writer.spreadsheet.del_worksheet( spreadsheet_writer.spreadsheet.worksheets()[0])

sheet_link = spreadsheet_writer.sheet_url
alert_message = ( f'Unmonitored `{env}` `{cloud}` resources - {sheet_link}')

send_notification( alert_message, yaml_inputs)

alert_message = []
for input in inputs.split(','):


set_input(input)

# This will read all the inputs provided in input_yaml
yaml_inputs = yaml_reader()

# Fetching the environment
env = yaml_inputs['env']

dcs = []
for dc in yaml_inputs['env_region_map']:
dcs.append(dc)

cloud = yaml_inputs['cloud']

if cloud == 'aws':

print('##################################################\n')
print('RUNNING ALARM CHECKER FOR AWS')
print('##################################################\n')

# Creating spreadsheets
aws_spreadsheet_writer = create_sheets(cloud, env, yaml_inputs)

# Geting buisness team map from consul host
business_team_map = get_business_team_map(yaml_inputs['buisness_team_map'])

has_aws_unmonitored_resources = aws_alarm_checker( env, yaml_inputs, business_team_map, dcs, aws_spreadsheet_writer)
if has_aws_unmonitored_resources:
aws_spreadsheet_writer.autoresize_spreadsheet()
aws_spreadsheet_writer.spreadsheet.del_worksheet( aws_spreadsheet_writer.spreadsheet.worksheets()[0])

sheet_link = aws_spreadsheet_writer.sheet_url
alert_message.append( f'Unmonitored `{env}` `{cloud}` resources - {sheet_link}')

elif cloud == 'azure':


print('##################################################\n')
print('RUNNING ALARM CHECKER FOR AZURE')
print('##################################################\n')

azure_spreadsheet_writer = create_sheets(cloud, env, yaml_inputs)
has_azure_unmonitored_resources = azure_alarm_checker( env, yaml_inputs,azure_spreadsheet_writer)

if has_azure_unmonitored_resources:
azure_spreadsheet_writer.autoresize_spreadsheet()
azure_spreadsheet_writer.spreadsheet.del_worksheet( azure_spreadsheet_writer.spreadsheet.worksheets()[0])

sheet_link = azure_spreadsheet_writer.sheet_url
alert_message.append( f'Unmonitored `{env}` `{cloud}` resources - {sheet_link}')

else:
raise Exception("Please use correct cloud, as this is not supported %s", cloud )


send_notification( alert_message)

if __name__ == '__main__':
main()
Loading

0 comments on commit 3684910

Please sign in to comment.