写一个weblogic的巡检脚本
时间: 2023-09-14 19:11:43 浏览: 247
weblogic巡检信息采集脚本
3星 · 编辑精心推荐
以下是一个基本的WebLogic巡检脚本,它将检查WebLogic服务器的健康状况并生成报告。
```bash
#!/bin/bash
# WebLogic Server Details
ADMIN_USERNAME="admin"
ADMIN_PASSWORD="password"
ADMIN_HOST="localhost"
ADMIN_PORT="7001"
# Report Location
REPORT_LOCATION="/path/to/report/logs"
# Check if the report location exists, otherwise create it
if [ ! -d "$REPORT_LOCATION" ]; then
mkdir -p "$REPORT_LOCATION"
fi
# Generate timestamp for report
TIMESTAMP=$(date +"%Y-%m-%d-%H-%M-%S")
REPORT_FILE="$REPORT_LOCATION/weblogic-report-$TIMESTAMP.txt"
# Connect to WebLogic Server
connectString="$ADMIN_USERNAME:$ADMIN_PASSWORD@$ADMIN_HOST:$ADMIN_PORT"
connect "$connectString"
# Health Check
echo "Server Health Check Report" > "$REPORT_FILE"
echo "" >> "$REPORT_FILE"
echo "--------------------------" >> "$REPORT_FILE"
echo "" >> "$REPORT_FILE"
echo "Checking Server Status..." >> "$REPORT_FILE"
echo "" >> "$REPORT_FILE"
status=$(nmConnect $connectString 2>&1)
if [[ "$status" == *"successfully"* ]]; then
echo "Server is Up and Running" >> "$REPORT_FILE"
else
echo "Server is Down" >> "$REPORT_FILE"
fi
echo "" >> "$REPORT_FILE"
echo "Checking Server Health..." >> "$REPORT_FILE"
echo "" >> "$REPORT_FILE"
health=$(serverStatus -all 2>&1)
echo "$health" >> "$REPORT_FILE"
echo "" >> "$REPORT_FILE"
echo "Checking JDBC Connection Pools..." >> "$REPORT_FILE"
echo "" >> "$REPORT_FILE"
pools=$(ls('/JDBCSystemResources'))
for pool in $pools
do
echo "Pool: $pool" >> "$REPORT_FILE"
echo "" >> "$REPORT_FILE"
cd("/JDBCSystemResources/$pool/JDBCResource/$pool")
cd("/JDBCDriverParams/NO_NAME_0/Properties/NO_NAME_0/Property/user")
username=$(cmo.getValue())
cd("../../../../../..")
cd("/JDBCConnectionPoolParams/NO_NAME_0")
initialCapacity=$(cmo.getInitialCapacity())
maxCapacity=$(cmo.getMaxCapacity())
capacityIncrement=$(cmo.getCapacityIncrement())
connectionTimeoutSeconds=$(cmo.getConnectionTimeoutSeconds())
inactiveConnectionTimeoutSeconds=$(cmo.getInactiveConnectionTimeoutSeconds())
statementTimeoutSeconds=$(cmo.getStatementTimeoutSeconds())
echo "Username: $username" >> "$REPORT_FILE"
echo "Initial Capacity: $initialCapacity" >> "$REPORT_FILE"
echo "Max Capacity: $maxCapacity" >> "$REPORT_FILE"
echo "Capacity Increment: $capacityIncrement" >> "$REPORT_FILE"
echo "Connection Timeout Seconds: $connectionTimeoutSeconds" >> "$REPORT_FILE"
echo "Inactive Connection Timeout Seconds: $inactiveConnectionTimeoutSeconds" >> "$REPORT_FILE"
echo "Statement Timeout Seconds: $statementTimeoutSeconds" >> "$REPORT_FILE"
echo "" >> "$REPORT_FILE"
done
echo "Report Generated at $REPORT_FILE"
```
该脚本使用WebLogic的Java Management Extensions (JMX) API执行健康检查并生成报告。您可以根据需要修改脚本并添加其他检查。
阅读全文