Chinaunix首页 | 论坛 | 博客
  • 博客访问: 346563
  • 博文数量: 38
  • 博客积分: 1289
  • 博客等级: 中尉
  • 技术积分: 533
  • 用 户 组: 普通用户
  • 注册时间: 2008-06-10 22:30
个人简介

Good Good Study. Day Day Up.

文章分类

全部博文(38)

文章存档

2018年(1)

2016年(3)

2015年(12)

2014年(7)

2013年(10)

2012年(5)

分类: 系统运维

2014-08-11 12:25:40

原理:通过调用 WAS 自带的脚本 wsadmin.sh 来获取实例的状态

操作系统版本:
[root]# head -1 /etc/redhat-release
Red Hat Enterprise Linux Server release 5.3 (Tikanga)

WAS 版本:
[root]# /opt/IBM/WebSphere/AppServer/bin/versionInfo.sh | grep -A 3 "Installed Product"
Installed Product
--------------------------------------------------------------------------------
Name                     IBM WebSphere Application Server - ND
Version                  7.0.0.25

代码:

check_was_state.sh

点击(此处)折叠或打开

  1. #!/bin/ksh
  2. WAS_IP="192.168.222.3"
  3. WAS_USERNAME="wasadmin"
  4. WAS_PASSWORD="wasadmin"
  5. WAS_INSTANCE_NAME="SampleServer1"
  6. WSADMIN="/opt/IBM/WebSphere/AppServer/bin/wsadmin.sh"
  7. FILE_STAT_LOG=was_stat_`date +"%Y%m%d_%H%M%S"`.log
  8. $WSADMIN -lang jython -host $WAS_IP -user $WAS_USERNAME -password $WAS_PASSWORD -f check_was_state.py > $FILE_STAT_LOG 2>&1

  9. grep "${WAS_INSTANCE_NAME}: STARTED" $FILE_STAT_LOG > /dev/null 2>&1
  10. if [ $? == 0 ]; then
  11.     echo "$WAS_IP $WAS_INSTANCE_NAME status is OK"
  12. else
  13.     echo "$WAS_IP $WAS_INSTANCE_NAME status is not OK"
  14. fi

check_was_state.py

点击(此处)折叠或打开

  1. import AdminUtilities

  2. # List servers with specified server type
  3. servers = AdminTask.listServers('-serverType APPLICATION_SERVER')

  4. # Convert Jython string to list
  5. servers = AdminUtilities.convertToList(servers)

  6. # Loop through each server in server list
  7. for aServer in servers:
  8.     # Obtain server and node names
  9.     sname = aServer[0:aServer.find("(")]
  10.     nname = aServer[aServer.find("nodes/")+6:aServer.find("servers/")-1]
  11.     runningServer = AdminControl.queryNames("type=Server,node=" + nname + ",name=" + sname + ",*")
  12.     if (len(runningServer) > 0):
  13.         serverState = AdminControl.getAttribute(runningServer, "state")
  14.     else:
  15.         serverState = "STOPPED"
  16.     # endIf
  17.     # Two different states: STARTED, STOPPED
  18.     print "%s: %s" % (sname,serverState)
  19. #endFor


阅读(7150) | 评论(2) | 转发(1) |
给主人留下些什么吧!~~

春风十里跑得快2018-09-05 16:03:08

这个python文件是不是必须的啊,感觉如果是集群的话那是不是很多个server不好处理啊?

whatislinux2014-09-01 18:09:13

点赞,感谢分享,收藏了。谢谢