Skip to content

Instantly share code, notes, and snippets.

@ejschaefer
Last active October 16, 2023 16:47
Show Gist options
  • Save ejschaefer/5aadaa1c531de7b619015e6f33851166 to your computer and use it in GitHub Desktop.
Save ejschaefer/5aadaa1c531de7b619015e6f33851166 to your computer and use it in GitHub Desktop.
Restart Websphere
{"instanceId":"$.detail.configuration.metrics[0].metricStat.metric.dimensions.InstanceId"}
{
"source": ["aws.cloudwatch"],
"detail-type": ["CloudWatch Alarm State Change"],
"resources": ["arn:aws:cloudwatch:us-east-1:123456789012:alarm:ServerCpuTooHigh"],
"detail": {
"state": {
"value": ["ALARM"]
}
}
}
---
schemaVersion: "2.2"
description: "Restart WebSphere"
mainSteps:
- action: "aws:runShellScript"
name: "RestartService"
inputs:
maxAttempts: 1
timeoutSeconds: 30
runCommand:
- |
#!/bin/bash
echo "Stopping WebSphere..."
/home/admin2/IBM/WebSphere/AppServer/profiles/AppSrv01/bin/stopServer.sh server1
echo "Starting WebSphere..."
/home/admin2/IBM/WebSphere/AppServer/profiles/AppSrv01/bin/startServer.sh server1
import boto3
import os
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)
ssm_client = None
def lambda_handler(event, context):
global ssm_client
logging.info(f"Event Received: {event}")
if ssm_client is None:
ssm_client = boto3.client('ssm')
instance_id = event['instanceId']
cmd_id = ssm_client.send_command(
InstanceIds=[instance_id],
DocumentName="restart_websphere",
CloudWatchOutputConfig={"CloudWatchOutputEnabled": True}
)
logger.info(f"Command Id: {cmd_id}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment