Friday, April 28, 2017

stop/start an application + wsadmin

# Application Name is ecv here in below example

import sys
def stopECV():
 serverstatus = AdminControl.completeObjectName('type=Application,name=ecv,*')
 if serverstatus == "":
  print "ECV is already in stopped state, no action taken"
 else:
  print "ECV is up  and Bringing it down"
  objNameStringServer = AdminControl.completeObjectName('WebSphere:type=Server,*')
  serverVersion = AdminControl.getAttribute(objNameStringServer,'serverVersion')
  tempserverVersion=serverVersion.split("Version               ",1)[1]
  serverVersion=tempserverVersion.split("ID",1)[0]
  tempserverVersion=serverVersion.strip()
  AdminControl.invoke('WebSphere:name=ApplicationManager,process=server1,platform=proxy,node=node01,version=' + tempserverVersion + ',type=ApplicationManager,mbeanIdentifier=ApplicationManager,cell=node01,spec=1.0', 'stopApplication', '[ecv]')
  serverstatus = AdminControl.completeObjectName('type=Application,name=ecv,*')
  if serverstatus == "":
   print "ECV is stopped"
  else:
   print "Some problem stopping the ECV, please contact FIL-AISWEBSupport@fil.com"

def startECV():
 serverstatus = AdminControl.completeObjectName('type=Application,name=ecv,*')
 if serverstatus == "":
  print "ECV is down bringing it up"
  objNameStringServer = AdminControl.completeObjectName('WebSphere:type=Server,*')
  serverVersion = AdminControl.getAttribute(objNameStringServer,'serverVersion')
  tempserverVersion=serverVersion.split("Version               ",1)[1]
  serverVersion=tempserverVersion.split("ID",1)[0]
  tempserverVersion=serverVersion.strip()
  AdminControl.invoke('WebSphere:name=ApplicationManager,process=server1,platform=proxy,node=node01,version=' + tempserverVersion + ',type=ApplicationManager,mbeanIdentifier=ApplicationManager,cell=node01,spec=1.0', 'startApplication', '[ecv]')
  serverstatus = AdminControl.completeObjectName('type=Application,name=ecv,*')
  if serverstatus == "":
   print "Some problem in bringing up the ECV, please contact FIL-AISWEBSupport@fil.com"
  else:
   print "ECV is up now"
 else:
  print "ECV is already in started state, no action taken"


def checkArguments():
 if len(sys.argv) == 1:
  appName=AdminApp.list().splitlines()
  if 'ecv' in appName:
   if sys.argv[0] == 'stopApplication':
    stopECV()
   elif sys.argv[0] == 'startApplication':
    startECV()
   else:
    print "Arguments can be either stopApplication or startApplication"
  else:
   print "Application ECV doesnt exist"
 else:
  print "Incorrect Number of Arguments"

checkArguments()

Thursday, November 3, 2016

sharedLibrary on ND Environment and command line

Usage: /tmp/test.jy a b "c;f;e;s"

import re

def main(clusterName, libraryName, classPath):
 print classPath
 allLibraryNames = AdminConfig.list('Library', AdminConfig.getid( '/Cell:'+ cellName +'/')).splitlines()
 for allLibraryName in allLibraryNames:
  if allLibraryName.find("cluster")==-1:
   sharedLibraryNotFound=1
  else:
   sharedLibraryFound=1
   allLibrary = allLibraryName.split("(")[0]
   if allLibrary == libraryName :
    print "Removing Shared Library"
    AdminConfig.remove(allLibraryName)
    AdminConfig.save()


def createSharedLibrary(clusterName, libraryName, classPath):
  print "Creating Shared Library"
  AdminConfig.create('Library', AdminConfig.getid('/Cell:'+ cellName +'/ServerCluster:'+ clusterName +'/'), '[[name ' + libraryName + '] [isolatedClassLoader false] [classPath '+ classPath +']]')
  AdminConfig.save()

arglen = len(sys.argv)
if arglen == 3 :
 arglength="TRUE"
else:
 print "Arguments were not 3"
 sys.exit(0)

first  =  sys.argv[0]
second = sys.argv[1]
third = sys.argv[2]

cellName = AdminControl.getCell()
clusterList = AdminConfig.list('ServerCluster', AdminConfig.getid( '/Cell:'+ cellName +'/')).splitlines()
for clusterNames in clusterList:
 clusterName = clusterNames.split("(")[0]
 if clusterName == first :
  main(sys.argv[0], sys.argv[1], sys.argv[2])
  createSharedLibrary(sys.argv[0], sys.argv[1], sys.argv[2])
 else:
  STATUS_FAILURE=1

RA

import re
resourceAdapters = AdminConfig.list('J2CResourceAdapter', AdminConfig.getid( '/Node:node01/')).splitlines()
for resourceAdapter in resourceAdapters:
 if resourceAdapter.find("ISRA")==-1:
  STATUS=1
 else:
  AdminConfig.remove(resourceAdapter)
  AdminConfig.save()
 
for resourceAdapter in resourceAdapters:
 if resourceAdapter.find("isra")==-1:
  STATUS=1
 else:
  AdminConfig.remove(resourceAdapter)
  AdminConfig.save()

s1=AdminConfig.getid('/Node:node01/')
for var in AdminConfig.list('VariableSubstitutionEntry', s1).splitlines():
 if AdminConfig.showAttribute(var, 'symbolicName') == 'VAH_NAME':
  vah=AdminConfig.showAttribute(var, 'value')
  rarFile = '/'+ vah +'/ISRA.rar'

node = AdminConfig.getid('/Cell:node01/Node:node01/')
option  = '[-rar.name  ISRA -rar.desc "New resource adapter"]'

AdminConfig.installResourceAdapter(rarFile, 'node01', option)
AdminConfig.save()

newra = AdminConfig.getid('/Cell:node01/Node:node01/J2CResourceAdapter:ISRA/')
ISRAJNDI = AdminTask.createJ2CConnectionFactory(newra, ['-name', 'J2CISRAConnectionFactory', '-jndiName', 'ISRAJNDI', '-connectionFactoryInterface', 'javax.resource.cci.ConnectionFactory'])
ISRASELLJNDI = AdminTask.createJ2CConnectionFactory(newra, ['-name', 'J2CISRAConnectionFactory', '-jndiName', 'ISRASELLJNDI', '-connectionFactoryInterface', 'javax.resource.cci.ConnectionFactory'])
AdminConfig.save()

ISRAJNDI_CustomProperties = AdminConfig.list("J2EEResourceProperty", ISRAJNDI).splitlines()
ISRASELLJNDI_CustomProperties = AdminConfig.list("J2EEResourceProperty", ISRASELLJNDI).splitlines()

for ISRAJNDI_CustomProperty in ISRAJNDI_CustomProperties:
 if ISRAJNDI_CustomProperty.find("DomainName") == -1:
  STATUS=1
 else:
  AdminConfig.modify(ISRAJNDI_CustomProperty, '[[name "DomainName"] [value "FIL_SIT1"]]')
  AdminConfig.save()

for ISRAJNDI_CustomProperty in ISRAJNDI_CustomProperties:
 if ISRAJNDI_CustomProperty.find("OrganizationName")==-1:
  STATUS=1
 else:
  AdminConfig.modify(ISRAJNDI_CustomProperty, '[[name "OrganizationName"] [value "FileNet"]]')
  AdminConfig.save()

for ISRAJNDI_CustomProperty in ISRAJNDI_CustomProperties:
 if ISRAJNDI_CustomProperty.find("LogFileName")==-1:
  STATUS=1
 else:
  AdminConfig.modify(ISRAJNDI_CustomProperty, '[[name "LogFileName"] [value "DealingISRA.log"]]')
  AdminConfig.save()

for ISRAJNDI_CustomProperty in ISRAJNDI_CustomProperties:
 if ISRAJNDI_CustomProperty.find("DeploymentInstance")==-1:
  STATUS=1
 else:
  AdminConfig.modify(ISRAJNDI_CustomProperty, '[[name "DeploymentInstance"] [value "1"]]')
  AdminConfig.save()

for ISRAJNDI_CustomProperty in ISRASELLJNDI_CustomProperties:
 if ISRAJNDI_CustomProperty.find("DomainName") == -1:
  STATUS=1
 else:
  AdminConfig.modify(ISRAJNDI_CustomProperty, '[[name "DomainName"] [value "FIL_SIT1"]]')
  AdminConfig.save()

for ISRAJNDI_CustomProperty in ISRASELLJNDI_CustomProperties:
 if ISRAJNDI_CustomProperty.find("OrganizationName")==-1:
  STATUS=1
 else:
  AdminConfig.modify(ISRAJNDI_CustomProperty, '[[name "OrganizationName"] [value "FileNet"]]')
  AdminConfig.save()

for ISRAJNDI_CustomProperty in ISRASELLJNDI_CustomProperties:
 if ISRAJNDI_CustomProperty.find("LogFileName")==-1:
  STATUS=1
 else:
  AdminConfig.modify(ISRAJNDI_CustomProperty, '[[name "LogFileName"] [value "DealingISRA.log"]]')
  AdminConfig.save()

for ISRAJNDI_CustomProperty in ISRASELLJNDI_CustomProperties:
 if ISRAJNDI_CustomProperty.find("DeploymentInstance")==-1:
  STATUS=1
 else:
  AdminConfig.modify(ISRAJNDI_CustomProperty, '[[name "DeploymentInstance"] [value "1"]]')
  AdminConfig.save()

Monday, September 19, 2016

single/multiple classloading

appName="XXX"
deployment_id = AdminConfig.getid ('/Deployment:'+ appName +'/')
appDeploy = AdminConfig.showAttribute(deployment_id, 'deployedObject')
AdminConfig.modify(appDeploy, '[[warClassLoaderPolicy "SINGLE"]]')
AdminConfig.save()

Friday, June 24, 2016

Enable/Disable Heuristic Hazard

> We can enable this parameter within an app as well as within the AppServer. Since, the change generated a different file with Random IDs. So, we cant have jython to change this within the Application.

Set acceptHeuristicHazard to true:

server = AdminConfig.getid('/Cell:node01/Node:node01/Server:server1/')
transactionService=AdminConfig.list("TransactionService", server)
AdminConfig.modify(transactionService, '[[acceptHeuristicHazard "true"]]')
AdminConfig.save()


Set acceptHeuristicHazard to false:

server = AdminConfig.getid('/Cell:node01/Node:node01/Server:server1/')
transactionService=AdminConfig.list("TransactionService", server)
AdminConfig.modify(transactionService, '[[acceptHeuristicHazard "false"]]')
AdminConfig.save()

Enable/Disable the Port in WAS

Disable: 

server = AdminConfig.getid('/Cell:node01/')
TCS=AdminConfig.list("TransportChannelService", server)
chains=AdminTask.listChains(TCS).splitlines()
for chain in chains:
 if chain.find("WCInboundAdmin(")==-1:
  STATUS=1
 else:
  AdminConfig.modify(chain,'[[enable "false"]]')
  AdminConfig.save()



Enable: 


server = AdminConfig.getid('/Cell:node01/')
TCS=AdminConfig.list("TransportChannelService", server)
chains=AdminTask.listChains(TCS).splitlines()
for chain in chains:
 if chain.find("WCInboundAdmin(")==-1:
  STATUS=1
 else:
  AdminConfig.modify(chain,'[[enable "true"]]')
  AdminConfig.save()

Thursday, June 2, 2016

ConfigureResourceURLs

import re
URLProvider=AdminConfig.getid('/Cell:node01/Node:node01/URLProvider:Default URL Provider/')
print "Deleting already existing URLs configured"
URLs=AdminConfig.list("URL",URLProvider).splitlines()
for URL in URLs :
 AdminConfig.remove(URL)
 AdminConfig.save()


print "Creating URLs under Resources"
AdminConfig.create('URL', AdminConfig.getid('/Cell:node01/Node:node01/URLProvider:Default URL Provider/'), '[[spec "<URL>"] [name "<Name>"] [description "<description>"] [category ""] [jndiName "<jndiName>"]]')

AdminConfig.save()


ConfigureASP

import re
node01=AdminConfig.getid('/Node:node01/')
print "Deleting ActivationSpecs in Default messaging provider "

mySIBJMSActivationSpecs = AdminTask.listSIBJMSActivationSpecs(node01).splitlines()
for sibJMSActivationSpecs in mySIBJMSActivationSpecs:
 AdminConfig.remove(sibJMSActivationSpecs)
 AdminConfig.save

print "Deleting ActivationSpecs in WebSphere MQ Resource Adapter "

ActivationSpec=AdminTask.listWMQActivationSpecs(node01).splitlines()
for activationSpec in ActivationSpec:
 AdminConfig.remove(activationSpec)
 AdminConfig.save()


print "Creating ActivationSpecs in WebSphere MQ Resource Adapter "

AdminTask.createWMQActivationSpec('"WebSphere MQ JMS Provider(cells/node01/nodes/node01|resources.xml#builtin_mqprovider)"', '[-name <Name> -jndiName "<jndiName>" -destinationJndiName "<destinationJndiName>" -destinationType <destinationType> -qmgrName <qmgrName> -wmqTransportType CLIENT -qmgrHostname <qmgrHostname> -qmgrPortNumber <qmgrPortNumber> -qmgrSvrconnChannel "<qmgrSvrconnChannel>" -sslType CENTRAL -authAlias "<authAlias>"]')

AdminConfig.save()

print "Listing and Adding extra custom property in Activation Specifications"

node01=AdminConfig.getid('/Node:node01/')
ActivationSpec=AdminTask.listWMQActivationSpecs(node01).splitlines()

for activationSpec in ActivationSpec:
 AdminConfig.create('J2EEResourceProperty', activationSpec, '[[name "messageRetention"] [type "java.lang.String"] [description "messageRetention"] [value "YES"] [required "false"]]')
 AdminConfig.create('J2EEResourceProperty', activationSpec, '[[name "clientID"] [type "java.lang.String"] [description "clientID"] [value ""] [required "false"]]')
 AdminConfig.create('J2EEResourceProperty', activationSpec, '[[name "providerVersion"] [type "java.lang.String"] [description "providerVersion"] [value ""] [required "false"]]')
 AdminConfig.save()

print "Updating Current Config"
node01=AdminConfig.getid('/Node:node01/')
ActivationSpec=AdminTask.listWMQActivationSpecs(node01).splitlines()
for activationSpec in ActivationSpec:
 properties=AdminConfig.list('J2EEResourceProperty', activationSpec).splitlines()
 for  property in properties:
  if property.find("arbitraryProperties")==-1:
   STATUS=1
  else:
   Value='was_stopEndpointIfDeliveryFails=\"true\",was_failureDeliveryCount=\"0\",sslType=\"SPECIFIC\",sslConfiguration=\"ENCMQSSLConfig\"'
   AdminConfig.modify(property, [["value" ,Value]])
   AdminConfig.save()
  if property.find("acknowledgeMode")==-1:
   STATUS=1
  else:
   AdminConfig.modify(property, '[[value "1"]]')
   AdminConfig.save()



Tuesday, March 1, 2016

Enable_TLSv12_for_Inbound_Communication

import re
print "Deleting TestSSLConfiguration if exists"
sslSettings=AdminTask.listSSLConfigs().splitlines()
for sslSetting in sslSettings:
 if sslSetting.find("TestSSLConfiguration") == -1:
  print " "
 else:
  print "Deleting TestSSLConfiguration"
  alias=sslSetting.split(" ")[1]
  AdminTask.deleteSSLConfig('-alias ' +alias +'')
  AdminConfig.save()
  print "Deleted %s" %alias

print " "

print "Creating TestSSLConfiguration"
AdminTask.createSSLConfig('[-alias TestSSLConfiguration -type JSSE -scopeName (cell):node01:(node):node01 -keyStoreName NodeDefaultKeyStore -keyStoreScopeName (cell):node01:(node):node01 -trustStoreName NodeDefaultKeyStore -trustStoreScopeName (cell):node01:(node):node01 ]')
AdminConfig.save()
print "Created TestSSLConfiguration"

print " "
print "Changing sslProtocol to TLSv1.2 for TestSSLConfiguration"
AdminTask.modifySSLConfig('[-alias TestSSLConfiguration -sslProtocol TLSv1.2]')
AdminConfig.save()
print "Changed sslProtocol to TLSv1.2 in TestSSLConfiguration"

print " "
print "Changing Ciphers for TestSSLConfiguration"
AdminTask.modifySSLConfig('[-alias TestSSLConfiguration -securityLevel CUSTOM -enabledCiphers "SSL_RSA_WITH_AES_128_CBC_SHA SSL_DHE_RSA_WITH_AES_128_CBC_SHA SSL_DHE_DSS_WITH_AES_128_CBC_SHA SSL_RSA_WITH_3DES_EDE_CBC_SHA SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA SSL_DHE_DSS_WITH_RC4_128_SHA SSL_RSA_WITH_AES_128_GCM_SHA256 SSL_RSA_WITH_AES_128_CBC_SHA256 SSL_DHE_RSA_WITH_AES_128_GCM_SHA256 SSL_DHE_RSA_WITH_AES_128_CBC_SHA256 SSL_DHE_DSS_WITH_AES_128_GCM_SHA256 SSL_DHE_DSS_WITH_AES_128_CBC_SHA256"]')
AdminConfig.save()
print "Changed Ciphers in TestSSLConfiguration"

print " "
print "Changing sslConfiguration for SSL_2"
server = AdminConfig.getid('/Cell:node01/Node:node01/Server:server1/')
Channel_Name = AdminConfig.list("SSLInboundChannel",server).splitlines()
for channel_name in Channel_Name :
 if channel_name.find("SSL_2")==-1:
  status="1"
 else:
  AdminConfig.modify(channel_name, '[[sslConfigAlias TestSSLConfiguration]]')
  AdminConfig.save()
  print "sslConfiguration changed for SSL_2"

print " "

Tuesday, February 16, 2016

SSO_Enable_requiresSSL

ltpaObjects = AdminConfig.list("LTPA")
ltpaId = ltpaObjects.split(lineSeparator)[0]
attrs1 = [["singleSignon", [["requiresSSL", "true"], ["enabled", "true"]]]]
AdminConfig.modify(ltpaId, attrs1)
AdminConfig.save()


ltpaObjects = AdminConfig.list("LTPA")
ltpaId = ltpaObjects.split(lineSeparator)[0]
attrs1 = [["singleSignon", [["requiresSSL", "false"], ["enabled", "true"]]]]
AdminConfig.modify(ltpaId, attrs1)
AdminConfig.save()

Tuesday, February 2, 2016

ConnectionFactory Change

Change:

import re
builtin=AdminConfig.getid("/Cell:node01/Node:node01/JMSProvider:WebSphere MQ JMS Provider/")
CF=AdminConfig.list('MQConnectionFactory',builtin).splitlines()
for ce in CF:
 if ce.find("cf_taskconsumer_dcfatcasvc")==-1:
  status=1
 else:
  AdminTask.modifyWMQConnectionFactory(ce, '[-sslType SPECIFIC -sslConfiguration MQSSLConfiguration]')
  AdminConfig.save()


Revert:

import re
builtin=AdminConfig.getid("/Cell:node01/Node:node01/JMSProvider:WebSphere MQ JMS Provider/")
CF=AdminConfig.list('MQConnectionFactory',builtin).splitlines()
for ce in CF:
 if ce.find("cf_taskconsumer_dcfatcasvc")==-1:
  status=1
 else:
  AdminTask.showWMQConnectionFactory(ce)

Thursday, January 28, 2016

Add/Delete Custom Property under Administration

Add:

import re
print "Listing All Servers"
appServer=AdminConfig.list('Server')
Administration=AdminConfig.list("ApplicationServer", appServer)
print "Adding Property com.ibm.websphere.threadmonitor.threshold"
AdminConfig.create('Property', Administration, '[[name "com.ibm.websphere.threadmonitor.threshold"] [description "com.ibm.websphere.threadmonitor.threshold"] [value 1800]]')
print "Property added com.ibm.websphere.threadmonitor.threshold, Now Saving the configuration"
AdminConfig.save()
print "Saved the configuration"
AdminConfig.list('Property',Administration)
print "List all Administration Properties"





Delete:
import re
print "Listing All Servers"
appServer=AdminConfig.list('Server')
Administration=AdminConfig.list("ApplicationServer", appServer)
all_property=AdminConfig.list('Property',Administration).splitlines()
for property in all_property:
 if property.find("com.ibm.websphere.threadmonitor.threshold")==-1:
  status=1
 else:
  print "Removing Property com.ibm.websphere.threadmonitor.threshold"
  AdminConfig.remove(property)
  print "Property com.ibm.websphere.threadmonitor.threshold removed, Now Saving the configuration"
  AdminConfig.save()
  print "Saved the configuration"


Wednesday, January 6, 2016

Add Custom Property within WebContainer Transport Chains

Application servers > server1 > Web container transport chains > WCInboundDefault > TCP inbound channel (TCP_2) > Custom properties


Change:
import re
server = AdminConfig.getid('/Cell:node01/Node:node01/Server:server1/')
Channel_Name = AdminConfig.list("TCPInboundChannel",server).splitlines()
for channel_name in Channel_Name :
 if channel_name.find("TCP_2")==-1:
  status=1
 else:
  AdminConfig.create('Property', channel_name, '[[validationExpression ""] [name "CookiesConfigureNoCache"] [description "to prevent expiration on drilldown when using WF back button"] [value "false"] [required "false"]]')
  AdminConfig.save()

 
 
Revert:
server = AdminConfig.getid('/Cell:node01/Node:node01/Server:server1/')
Channel_Name = AdminConfig.list("TCPInboundChannel",server).splitlines()
for channel_name in Channel_Name :
 if channel_name.find("TCP_2")==-1:
  status=1
 else:
  PROPERTY_NAME=AdminConfig.list('Property', channel_name).splitlines()
  for property_name in PROPERTY_NAME:
   if property_name.find("CookiesConfigureNoCache")==-1:
    status=2
   else:
    AdminConfig.remove(property_name)
    AdminConfig.save()

Wednesday, December 23, 2015

Turn "Allow Asynchronous Request Dispatcher ON/Off"

Server -> Application Server -> Web Container Settings -> WebContainer -> Asynchronous Request Dispatching

wsadmin Script to do the needful:

allServers=AdminConfig.list('Server')
server_name_web=AdminConfig.list("WebContainer",allServers)
AdminConfig.showAttribute(server_name_web,'allowAsyncRequestDispatching')
AdminConfig.modify(server_name_web,'[[allowAsyncRequestDispatching false]]')
AdminConfig.save()
AdminConfig.showAttribute(server_name_web,'allowAsyncRequestDispatching')

Monday, October 26, 2015

Find custom property present in what all database

import re
cell=AdminControl.getCell()
ds=AdminConfig.list('DataSource', AdminConfig.getid( '/Cell:'+cell+'/')).splitlines()
for data in ds:
 propSet = AdminConfig.showAttribute(data,'propertySet')
 name=AdminConfig.showAttribute(data,'name')
 custom_properties=AdminConfig.showall(propSet).splitlines()
 for single_custom_property in custom_properties:
  if single_custom_property.find("webSphereDefaultIsolationLevel")==-1:
   STATUS=1
  else:
   print name

Thursday, October 8, 2015

enable_disable_ecv.jy


Script to run:
~/profile/bin/wsadmin.sh -lang jython -f enable_disable_ecv.jy true (to enable)
~/profile/bin/wsadmin.sh -lang jython -f enable_disable_ecv.jy false (to disable)


import re
import os
import sys
first_arg=sys.argv[0]

app_name_all=AdminApp.list().splitlines()
for ecv in app_name_all:
 if ecv.find("ecv")==-1:
  STATUS=1
 else:
  deploymentID=AdminConfig.getid ('/Deployment:'+ ecv +'/')
  deploymentObj1 = AdminConfig.showAttribute(deploymentID, 'deployedObject')
  targetMap1 = AdminConfig.showAttribute(deploymentObj1, 'targetMappings')
  targetMap1 = targetMap1[1:len(targetMap1)-1].split(" ")
  for targetMapping in targetMap1:
   if first_arg == "true":
    AdminConfig.modify(targetMapping, [["enable", "true"]])
    AdminConfig.save()
   elif first_arg == "false":
    AdminConfig.modify(targetMapping, [["enable", "false"]])
    AdminConfig.save()
   else:
    print "Argument should be true/false"

Monday, September 21, 2015

Script to shutdown autorotation of SystemOut.log and SystemErr.log

server_Name=AdminConfig.list('Server').splitlines()
for serverName in server_Name :
log_error=AdminConfig.showAttribute(serverName, 'errorStreamRedirect')
log_output=AdminConfig.showAttribute(serverName, 'outputStreamRedirect')
AdminConfig.modify(log_error, [['rolloverType', "NONE"]])
AdminConfig.modify(log_error, [['maxNumberOfBackupFiles', 1]])
AdminConfig.modify(log_output, [['rolloverType', "NONE"]])
AdminConfig.modify(log_output, [['maxNumberOfBackupFiles', 1]])
AdminConfig.save()

Sunday, September 20, 2015

Test Connection to all Datasources

import re
ds = AdminConfig.list('DataSource', AdminConfig.getid( '/Cell:node01/')).splitlines()
for datasourcename in ds:
 if datasourcename.find("DefaultEJBTimerDataSource")== -1:
   print AdminControl.testConnection(datasourcename)
 else:
  status=1
 
   

Wednesday, September 16, 2015

create_webContainer_custom_property.jy

import re
allServers=AdminConfig.list('Server').splitlines()
for allservers in allServers :
 if allservers.find("nodeagent")== -1 :
  if allservers.find("dmgr") == -1 :
   print allservers
   server_name_web=AdminConfig.list("WebContainer",allservers)
   AdminConfig.create('Property', server_name_web, '[[validationExpression ""] [name "com.ibm.ws.webcontainer.disablexPoweredBy"] [description "com.ibm.ws.webcontainer.disablexPoweredBy"] [value "true"] [required "false"]]')
   AdminConfig.save()
  else:
   status=1
 else:
  status=1

Monday, September 14, 2015

Jython Script to Map Shared Library with App Server

import re
Library_names = AdminConfig.list('Library', AdminConfig.getid('/Cell:node01/')).splitlines()
for libraryname in Library_names:
 if libraryname.find("PV_SHARED_LIB")== -1 :
  status=1
 else:
  AdminConfig.remove(libraryname)
  AdminConfig.save()

server = AdminConfig.getid('/Cell:node01/Node:node01/Server:server1/')
AdminConfig.create('Library',server, [['name', "PV_SHARED_LIB"], ['classPath', "${USER_INSTALL_ROOT}/installedApps/node01/dcpvEAR.ear/dcpv.war/WEB-INF/lib/wsdl4j-1.6.2.jar;${USER_INSTALL_ROOT}/installedApps/node01/dcpvEAR.ear/dcpv.war/WEB-INF/lib/httpclient-4.3.6.jar;${USER_INSTALL_ROOT}/installedApps/node01/dcpvEAR.ear/dcpv.war/WEB-INF/lib/httpcore-4.3.3.jar;${USER_INSTALL_ROOT}/installedApps/node01/dcpvEAR.ear/dcpv.war/WEB-INF/lib/jackson-all-1.9.11.jar"]])
AdminConfig.save()
Classloader1 = AdminConfig.list('Classloader', AdminConfig.getid( '/Cell:node01/Node:node01/Server:server1/')).splitlines()
for classloader in Classloader1 :
 AdminConfig.remove(classloader)
 AdminConfig.save()
 print "Classloader Removed"
ApplicationServer = AdminConfig.list('ApplicationServer', AdminConfig.getid('/Cell:node01/Node:node01/Server:server1/'))
Classloader = AdminConfig.create('Classloader', ApplicationServer, '[[mode PARENT_LAST]]')
AdminConfig.save()
print "Classloader Created"
Classloader1 = AdminConfig.list('Classloader', AdminConfig.getid('/Cell:node01/Node:node01/Server:server1/'))
AdminConfig.create('LibraryRef', Classloader1, [['libraryName', "PV_SHARED_LIB"], ['sharedClassloader', "true"]])
AdminConfig.save()
print "Shared Library mapped with the classloader"

Friday, August 28, 2015

Display Custom Services

Custom_Services = AdminConfig.list('CustomService', AdminConfig.getid( '/Cell:node01/Node:node01/Server:server1/')).splitlines()
for customService in Custom_Services:
 print "-----------------------------------------------------------------------------------------------------------"
 print ('DisplayName = ' , AdminConfig.showAttribute(customService, "displayName" ))
 print ('Classpath = ' , AdminConfig.showAttribute(customService, "classpath" ))
 print ('Enable = ' , AdminConfig.showAttribute(customService, "enable" ))
 print ('ExternalConfigUrl = ' , AdminConfig.showAttribute(customService, "externalConfigURL" ))
 print ('Description = ' , AdminConfig.showAttribute(customService, "description" ))
 print ('ClassName = ' , AdminConfig.showAttribute(customService, "classname" ))

Monday, August 10, 2015

Add Shared Library to all Modules

import sys

appName =Give your application name - should be same which is mentioned on console
sharedLibraryName =Give your shared library name - should be same which is mentioned on console

def bindSharedLibrary(appName,sharedLibName):
    deployment_id = AdminConfig.getid ('/Deployment:'+ appName +'/')
    if (len(deployment_id) == 0):
        print ("Application with name " + appName + " does not exists")
        sys.exit(1)

    print("Binding shared lib " + sharedLibraryName + " to application " + appName)

    appDeploy = AdminConfig.showAttribute(deployment_id, 'deployedObject')
    classLoad1 = AdminConfig.showAttribute(appDeploy, 'classloader')

    AdminConfig.create('LibraryRef', classLoad1, [['libraryName', sharedLibraryName]])

    print("Shared lib " + sharedLibraryName + " bound to application " + appName + " successfully")


bindSharedLibrary(appName,sharedLibraryName)
AdminConfig.save()



Certificate Information

import re

for ks in AdminTask.listKeyStores('[-all true -keyStoreUsage SSLKeys ]').splitlines():
        keystoreName =  AdminConfig.showAttribute(ks, 'name')
        ms = AdminConfig.showAttribute(ks, 'managementScope')
        scopeName = AdminConfig.showAttribute(ms, 'scopeName')

        signerCertsFound=0
        for cert in AdminTask.listSignerCertificates('[-keyStoreName '+keystoreName+' -keyStoreScope '+scopeName+']').splitlines():
                for property in re.split("\] \[", cert):
                        if(re.search("\[\[",  property)):
                                tmp = property
                                property = re.split("\[\[",tmp)[1]
                        if(re.search("] ]",  property)):
                                tmp = property
                                property = re.split("] ]",tmp)[0]
                        if(re.search("alias", property)):
                                alias = re.split("\s+", property)[1]
                                print alias
                        if(re.search("fingerPrint", property)):
                                fingerprint = re.split("\s+", property)[1]
                                print fingerprint

Check NodeSync State

import re
cells = AdminConfig.list("Cell" )
NodeName=AdminTask.listNodes().splitlines()
for node_name in NodeName:
  if node_name.find("Node") == -1:
   status=1
  else:
   node_Object=AdminControl.completeObjectName('type=NodeSync,node='+node_name+',*')
   status=AdminControl.invoke(node_Object, 'isNodeSynchronized')
   if status == 'true' :
    print node_name,
    print "is synchronized"
   else :
    print node_name,
    print "is not synchronized - ",
    print "Consult Middleware Team for further assistance"

Wednesday, May 13, 2015

Create/Remove Custom Properties

./wsadmin.sh -lang jython -f /tmp/custom.jy

Contents of custom.jy:

server1 = AdminConfig.getid('/Server:server1/')
print server1
jvm = AdminConfig.list('JavaVirtualMachine',server1)
import java
lineSeparator = java.lang.System.getProperty('line.separator')
arrayJVMs = jvm.split(lineSeparator)
cjvm = arrayJVMs[0]
attr_name  = ['name', "com.fgpi.apps.dbweb.serviceEndPoint"]
attr_value = ['value', "https://test"]
attr_required = ['required', "false"]
attr_description = ['description', "DBWeb Service URL"]
attr_list = [attr_name, attr_value, attr_required, attr_description]
property=['systemProperties',[attr_list]]
AdminConfig.modify(cjvm, [property])
AdminConfig.save()


server1=AdminConfig.getid('/Server:server1/')
JVM=AdminConfig.list('JavaVirtualMachine',server1)
properties=AdminConfig.list('Property',JVM).splitlines()
for property in properties:
 if property.find("keyLocation")==-1:
  STATUS=1
 else:
  AdminConfig.modify(property,'[[value "/${VAH_NAME}/.ssh/id_rsa"]]')
  AdminConfig.save()


import re
server1=AdminConfig.getid('/Server:server1/')
JVM=AdminConfig.list("JavaVirtualMachine",server1)
AdminConfig.modify(JVM,'[[verboseModeClass true]]')
properties=AdminConfig.list("Property",JVM)
for property in properties:
 if property.find("javax.net.debug")==-1:
  STATUS=1
 else:
  AdminConfig.create('Property',JVM,'[[name "javax.net.debug"] [value "true"] [description "javax.net.debug"] [required "false"]]')



Remove Custom Property: - if property name which we need to remove is business.unit.name

import re
server1 = AdminConfig.getid('/Server:server1/')
jvm = AdminConfig.list('JavaVirtualMachine',server1)
property=AdminConfig.list('Property', jvm).splitlines()
for property_name in property:
 if property_name.find("business.unit.name") == -1:
  status=1
 else :
  AdminConfig.remove(property_name)
  AdminConfig.save()




wsadmin.sh to determine Version

Shell Script:

LOGFILE="/tmp/test.log"
~/profile/bin/wsadmin.sh -lang jython -f /tmp/test.jy > $LOGFILE
cat $LOGFILE | grep -v Directory | grep Version | awk -F " " '{print $NF}'
rm $LOGFILE


Content of Jython Script:
objNameStringServer = AdminControl.completeObjectName('WebSphere:type=Server,*')
serverVersion = AdminControl.getAttribute(objNameStringServer,'serverVersion')
print serverVersion

Friday, May 8, 2015

Namespace

bid = AdminConfig.getid('/StringNameSpaceBinding:/')
bindings = bid.split("\n")
for binding in bindings:
 name1 = AdminConfig.showAttribute(binding,'name')
 if name1 == 'isWLMEnable' :
   string = AdminConfig.showAttribute(binding,'stringToBind')
   if string == 'false' :
        AdminConfig.modify(binding, '[[stringToBind "true"]]')
   elif string == 'true' :
        AdminConfig.modify(binding, '[[stringToBind "false"]]')
   else :
        print "Uncertain, don't plan anything"

AdminConfig.save()

Sunday, June 1, 2014

Heap Modification

# Use: wsadmin.sh -f HeapSizeModification.jacl
# This takes two arguements the string for initialHeapSize and MaxHeapSize to be updated (For E.g. if i have 10 JVMs (have a common) pattern of (s01) in the name

ih=sys.argv[0]
mh=sys.argv[1]

set allServers [$AdminConfig list Server ]
foreach vm $allServers {
        if { [regexp s01 [$AdminConfig showAttribute $vm name] ]==1
        } then {
        #puts "Found [$AdminConfig showAttribute $vm name]" ;
        lappend server_ids $vm ; }
        }
foreach server $server_ids {
        set jvm_id [$AdminConfig list JavaVirtualMachine $server] ;
        puts [$AdminConfig showAttribute $server name] ;
        set oldargs [$AdminConfig showAttribute $jvm_id initialHeapSize] ;
    set newargs [$AdminConfig showAttribute $jvm_id maximumHeapSize] ;
        puts "OLD: $oldargs" ;
        puts "NEW: $newargs" ;
        set args {}
        lappend args [list initialHeapSize $ih] ;
                lappend args [list maximumHeapSize $mh] ;
    #puts "Setting: $args" ;
        $AdminConfig modify $jvm_id $args ;
        }
        $AdminConfig save





server = AdminConfig.getid('/Server:server1/')
jvm = AdminConfig.list('JavaVirtualMachine', server)
AdminConfig.showAttribute(jvm, 'initialHeapSize')

AdminConfig.showAttribute(jvm, 'maximumHeapSize')
AdminConfig.modify(jvm,'[[maximumHeapSize 2048]]')
AdminConfig.modify(jvm,'[[initialHeapSize 512]]')
AdminConfig.save()


Update Generic JVM Argument

import sys
import os
server1=AdminConfig.getid('/Server:server1/')

JVM=AdminConfig.list('JavaVirtualMachine', server1)

OLD=AdminConfig.showAttribute(JVM, 'genericJvmArguments')
new="-Xshareclasses:none"
newArgs= OLD + " " + new
AdminConfig.modify(JVM, [['genericJvmArguments', newArgs]])
AdminConfig.save()

Disable/Enable Verbose GC

# Use: wsadmin.sh -f enableVerboseModeGarbageCollection.jacl 
#For enabling, use the parameter true and for disabling, use the parameter as false

set allServers [$AdminConfig list Server ]
foreach vm $allServers {
        if { [regexp dmgr [$AdminConfig showAttribute $vm name] ]==1
        } then {
        lappend server_ids $vm ; }
        }
foreach server $server_ids {
        set jvm_id [$AdminConfig list JavaVirtualMachine $server] ;
        puts [$AdminConfig showAttribute $server name] ;
        set oldargs [$AdminConfig showAttribute $jvm_id verboseModeGarbageCollection ] ;
        set args {}
        lappend args [list verboseModeGarbageCollection "true"] ;
        $AdminConfig modify $jvm_id $args ;
        }
        $AdminConfig save

Like for example I have 40 JVMs and have a pattern (s01) common to them then i will edit my script as below: 

set allServers [$AdminConfig list Server ]
foreach vm $allServers {
        if { [regexp s01 [$AdminConfig showAttribute $vm name] ]==1
        } then {
        lappend server_ids $vm ; }
        }
foreach server $server_ids {
        set jvm_id [$AdminConfig list JavaVirtualMachine $server] ;
        puts [$AdminConfig showAttribute $server name] ;
        set oldargs [$AdminConfig showAttribute $jvm_id verboseModeGarbageCollection ] ;
        set args {}
        lappend args [list verboseModeGarbageCollection "true"] ;
        $AdminConfig modify $jvm_id $args ;
        }
        $AdminConfig save

List all Servers of the node

#USage: bin/wsadmin.sh –lang jython –f FILE_NAME NODE_NAME

n1 = sys.argv[0]
#
#
plist = "[-serverType APPLICATION_SERVER -nodeName " + n1 + "]" print plist
#
slist = AdminTask.listServers(plist).split("\n")
#

for s in slist: print s continue






Understanding WSAdmin

The wsadmin commands can be divided up into four basic groups (actually objects): AdminApp, AdminConfig, AdminControl, AdminTask, and Help.


AdminApp is the set of commands involved with the installation, removal and editing of applications.  The best way to find information on the available commands is to search on “AdminApp” in the InfoCenter and select the result named “Commands for the AdminApp object”.

AdminConfig is the set of commands used to alter specific items within the configuration. There are commands within the AdminConfig object that allow you to create, remove,
and modify attributes of objects within the configuration.  The best way to find information on the available commands is to search on “AdminConfig” in the InfoCenter and select the result named “Commands for the AdminConfig object”.

AdminControl is the set of commands used to control objects within the configuration. These are the commands used to start and stop servers, start and stop applications, test connections, start node synchronization, etc.  The best way to find information on the available commands is to search on “AdminControl” in the InfoCenter and select the result named “Commands for the AdminControl object”.

AdminTask is the set of commands used to perform specific tasks using the wsadmin interface.  It would be used for such things as creating or deleting a server, managing the port configuration, running reports on the configuration, etc.  Most everything that you would do with the AdminTask commands could also be done using combinations of the AdminApp, AdminConfig, and AdminControl commands, but someone in wsadmin development has packaged them up into useful commands and delivered them under the AdminTask object.  The best way to find information on the available commands is to search on “AdminTask” in the InfoCenter and select the result named “Commands for the AdminTask object”.  At the bottom of that entry you would find links to the commands associated with the various groups of the AdminTask object (ClusterConfigCommands, PortManagement, AdminstrationReport, etc.).

There is help available at a “base” level:



print Help.help();


will give a list of the objects and statements for which help is available.

There is help available on each of the other objects mentioned, for instance the AdminTask object:

print AdminTask.help()

will provide a list of the available help options for the AdminTask object.  Drilling down a further level:

print AdminTask.help(“-commands”)

will print a list of all of the commands available under the AdminTask object. Continuing to an even finer level:

print AdminTask.help("listServerPorts")

will provide help on the specific command, listServerPorts, of the AdminTask object.

Naturally, the most difficult part of writing a script is to know which of the hundreds of commands is the correct one for each task.  There is some help available in the WebSphere V6.1 adminconsole, using the command assistance notifications.  To enable this option, you set it in the adminconsole >> System administration >> Console preferences section.




Once it is set, after you have done something in the adminconsole that you would like to duplicate in a script, you would click on the command assistance link in the help box on the right hand side of the console.


If Global Security is turned off, the script will run without any prompting of username/password. 

If Global Security is turned ON, the script will prompt for username and password, to disable prompting follow below 2 methods:

1) Run the script line below:
 bin/wsadmin.sh -username wasadmin -password wasadmin –lang jython –f FILE_NAME NODE_NAME 

2) Open soap.client.props under <PROFILE_PATH>/properties and do below settings:



  •   com.ibm.SOAP.securityEnabled=true
  •   com.ibm.SOAP.loginUserid=wasadmin 
  •   com.ibm.SOAP.loginPassword=wasadmin