On Mon, 2008-03-17 at 12:47 -0400, Michael DeHaan wrote:
> Take a look at what modules are available now, and if you need more
> functionality added to them, feel free to submit patches for those.
I wrote my first version of jboss module. \o/
this module represent client-side all stuff I write on sample test some
day ago.
ATM this module allow user to launch:
- status() : give information about running istances
- check() : perform some basic tests (ATM it checks only up istances
which don't listen on any ports)
- search_by_istance(), search_by_address, search_by_port(): give
information about particular istance name, port and address (now are
three differents searches...it will be more useful if is possible to
combine searches)
Basically I use sub_process.Popen to launch netstat and ps ax. Is this
the right solution?
Now I'm working now on start() and stop() methods.
If you have ideas about some stuff to be added or error...tell me ;-)
bye
Luca
--
Today is Prickle-Prickle, the 6th day of Discord in the YOLD 3174
#
# Copyright 2008
# Luca Foppiano <[EMAIL PROTECTED]>
# Simone Pucci <[EMAIL PROTECTED]>
# Byte-code srl www.byte-code.com
#
# This software may be freely redistributed under the terms of the GNU
# general public license.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
import func_module
import sub_process
import codes
class JBoss(func_module.FuncModule):
version = "0.0.1"
api_version = "0.0.1"
description = "JBoss monitoring and control module"
def version(self):
"""
Return jboss version
TODO: implementation
"""
return "version"
def status(self):
"""
Get jboss information
(istance name, ports, bind address, pid)
"""
cmd = sub_process.Popen(["/bin/ps", "ax"], executable="/bin/ps",
stdout=sub_process.PIPE,
stderr=sub_process.PIPE,
shell=False)
data, error = cmd.communicate()
# We can get warnings for odd formatting. warnings != errors.
if error and error[:7] != "Warning":
raise codes.FuncException(error.split('\n')[0])
results = []
for x in data.split("\n"):
tokens = x.split()
results.append(tokens)
output = []
for items in results:
if "-Dprogram.name=run.sh" in items:
for item in items:
if "java" in item:
java = True
if java == True:
if items.__contains__("-c"):
istance = items[items.index("-c")+1]
else:
istance = None
if items.__contains__("-b"):
address = items[items.index("-b")+1]
else:
address = None
output.append((int(items[0]),istance,address,[]))
# Retrieve information about network (netstat -tupln)
cmd = sub_process.Popen(["/bin/netstat", "-tupln"],
executable="/bin/netstat",
stdout=sub_process.PIPE,
stderr=sub_process.PIPE,
shell=False)
data, error = cmd.communicate()
# We can get warnings for odd formatting. warnings != errors.
if error and error[:7] != "Warning":
raise codes.FuncException(error.split('\n')[0])
results = []
for x in data.split("\n"):
tokens = x.split()
results.append(tokens)
debug = []
for string in results:#netstat_list:
address = None
port = None
pid = None
try:
address_port = string[3]
pid_name = string[6]
except:
address_port = None
pid_name = None
if address_port != None:
try:
address = string[3].split(":")[0]
port = int(string[3].split(":")[1])
except:
address = None
port = None
if pid_name != None:
try:
pid = int(pid_name.split("/")[0])
except:
pid = None
if pid != None:
for data in output:
debug.append(data)
if data[0] == pid:
#verify address
if address != None:
if data[2] == address:
data[3].append(port)
return output
def check(self, status=None):
"""
Check if jboss istances works, controls:
* check if istance listen on ports
Return values:
- istance up but not listen = (-1, istances with problem)
- OK = (0, [])
"""
if(status == None):
data = self.status()
else:
data = status
result = []
code = 0
for item in data:
if len(item[3]) == 0:
code = -1
result.append(item)
return (code, result)
def search_by_port(self, port, status=None):
"""
Search istance by listening port
"""
if(status == None):
data = self.status()
else:
data = status
founded = []
for item in data:
for ports in item[3]:
if port == ports:
founded.append(item)
return founded
def search_by_istance(self, istance, status=None):
"""
Search istance by istance name
"""
if(status == None):
data = self.status()
else:
data = status
founded = []
for item in data:
if item[1] == istance:
founded.append(item)
return founded
def search_by_address(self, address, status=None):
"""
Search istance by bind address
"""
if(status == None):
data = self.status()
else:
data = status
founded = []
for item in data:
if item[2] == address:
founded.append(item)
return founded
'''
def start(self, address="127.0.0.1", istance="default"):
"""
Start a jboss istance
"""
jboss_path="/var/lib/jboss-4.2.2.GA"
jboss_run_path=jboss_path+"/bin/run.sh"
status=self.status()
if len(self.search_by_address(address=address, status=status)) != 0:
return "Another istances listening on this address, "
if len(self.search_by_istance(istance=istance, status=status)) != 0:
return result + str("This istances is just istanced")
arguments = boss_run_path+" -c "+istance+" -b "+address
cmd = sub_process.Popen(["/bin/sh", arguments], executable="/bin/sh",
stdout=sub_process.PIPE,
stderr=sub_process.PIPE,
shell=False)
data, error = cmd.communicate()
if error and error[:7] != "Warning":
raise codes.FuncException(error.split('\n')[0])
return "OK, instance "+ istance +"started on address "+address
def stop(self, address="127.0.0.1"):
"""
Stop a jboss istance, now use a standarda JNDI port
1099. By default stop che localhost bind istance
TODO: give more flexibility
"""
jboss_path="/var/lib/jboss-4.2.2.GA"
jboss_sd_path=jboss_path+"/bin/shutdown.sh"
data = self.search_by_address("127.0.0.1")
if len(data) == 0:
return "Istance on "+ address +" not running"
arguments = " -s jnp://"+address+":1099"
exe = "/bin/sh "+jboss_sd_path
cmd = sub_process.Popen([exe, arguments], executable=exe,
stdout=sub_process.PIPE,
stderr=sub_process.PIPE,
shell=False)
data, error = cmd.communicate()
if error and error[:7] != "Warning":
raise codes.FuncException(error.split('\n')[0])
return "OK, stopped istance listening address "+address
'''
#!/usr/bin/env python
import func.overlord.client as fc
print fc.Client("*.byte-code.lan").jboss.status()
print fc.Client("*.byte-code.lan").jboss.check()
print fc.Client("*").jboss.search_by_address("127.0.0.1")
print fc.Client("*").jboss.search_by_istance("default")
print fc.Client("*").jboss.search_by_port(8080)
_______________________________________________
Func-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/func-list