Posts

Showing posts from 2018

Script - Server level

____ Server to Azure Blob ____ #!/bin/bash DATE=$(date +"%m%d%y"-%H%M%S) mkdir -p /mnt/backup/codebase/GFS_SHARE_BACKUP/asterguidelines/ mkdir -p /mnt/backup/codebase/SITES_ENABLED_BACKUP/asterguidelines/ Code_path=/opt/httpdocs/asterguidelines/ Sites_enabled_path=/etc/apache2/sites-enabled/asterguidelines* Code_Backup_Path=/mnt/backup/codebase/GFS_SHARE_BACKUP/asterguidelines/ Sites_enabled_Backup_Path=/mnt/backup/codebase/SITES_ENABLED_BACKUP/asterguidelines/ export file=$Sites_enabled_Backup_Path$DATE-sites-enabled.zip &&  zip -r $file $Sites_enabled_path export file1=$Code_Backup_Path$DATE-gfs-share.zip  &&  zip -r $file1 $Code_path sleep 5s export AZURE_STORAGE_ACCOUNT=backupnewcost export AZURE_STORAGE_ACCESS_KEY=xSW5Pj8yi5ESXJuWX1BYe5yTJiVktJWLqb0ejE1r3k01+Hz+3jMZpVboP3C8CEPFfHkTt6YRf5qIEFMM5HpsXA== export container_name=asterguidelines export blob_name=$DATE-sites-enabled.zip export blob_name1=$DATE-gfs-share.zip #export image_to...

Script - Stop Start & Reboot

___ Stop __ import boto3 # Enter the region your instances are in. Include only the region without specifying Availability Zone; e.g., 'us-east-1' region = 'us-east-1' # Enter your instances here: ex. ['X-XXXXXXXX', 'X-XXXXXXXX'] instances = ['i-064ffac2782e94bdf'] def lambda_handler(event, context):    ec2 = boto3.client('ec2', region_name=region)    ec2.stop_instances(InstanceIds=instances)    print 'stopped your instances: ' + str(instances) ___ Start ____ import boto3 import logging #setup simple logging for INFO logger = logging.getLogger() logger.setLevel(logging.INFO) #define the connection ec2 = boto3.resource('ec2',region_name='us-east-1') def lambda_handler(event, context):    # Use the filter() method of the instances collection to retrieve    # all stooped EC2 instances.    filters = [{        ...

Script - Reserved Instance Expire

_____ Reserved Instance Expire _____ import boto3 import datetime from dateutil.tz import tzutc from botocore.exceptions import ClientError def handler(event,context):    SENDER = "worxogo.alerts@powerupcloud.com"    #RECIPIENT = ["worxogo.alerts@powerupcloud.com","kanishk@worxogo.com"]    RECIPIENT = ["worxogo.alerts@powerupcloud.com","infra-ops@worxogo.com"]    AWS_REGION = "us-east-1"    SUBJECT = "Reserved Instance Expiry Information"        access_key = "AKIAIVRHBSCHEPQQOHKQ"    secret_key = "8eyda64KZIwc3QFniyYsndaF+dUOSnS3uL/1Xx+5"        client = boto3.client('ec2', aws_access_key_id=access_key, aws_secret_access_key=secret_key,                           ...

Script - Unused EBS & EIP

__________ Unused EBS Volume _________ import boto3 import logging from datetime import * #setup simple logging for INFO logger = logging.getLogger() logger.setLevel(logging.WARNING) ### Variables Declared regions = ['us-east-1', 'us-east-2', 'us-west-1','us-west-2', 'ap-south-1', 'ap-northeast-2', 'ap-southeast-1', 'ap-southeast-2', 'ap-northeast-1', 'eu-central-1', 'eu-west-1', 'sa-east-1'] Account_Name = ['Worxogoprod'] AccessID = ['AKIAJRBAJGZKMR36Y6UA'] SecretID = ['UoO+4574nDnqq57zlVCAYy+w0IOMur5vw4fWnvxy'] sns = boto3.resource('sns') platform_endpoint = sns.PlatformEndpoint('arn:aws:sns:ap-southeast-1:316720341464:ELB-unused-alerts') #set the date to today for the snapshot today = datetime.now().date() missingReport=" " def lambda_handler(event, context):    missingReport=" "    for...