Hi, this is jboss module with git patch format. ATM it can monitor jboss istances, as explained few day ago :) Luca --- func/minion/modules/jboss.py | 243 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 243 insertions(+), 0 deletions(-) create mode 100644 func/minion/modules/jboss.py diff --git a/func/minion/modules/jboss.py b/func/minion/modules/jboss.py new file mode 100644 index 0000000..b7664a5 --- /dev/null +++ b/func/minion/modules/jboss.py @@ -0,0 +1,243 @@ +# +# Copyright 2008 +# Luca Foppiano <lfoppiano@xxxxxxxxxxxxx> +# Simone Pucci <spucci@xxxxxxxxxxxxx> +# 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 +import process +import networktest + +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) + """ + processo = process.ProcessModule() + results = processo.info("ax") + + 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) + + net_status = networktest.NetworkTest() + results = net_status.netstat("-tupln") + + 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 + +''' + -- 1.5.4.1 _______________________________________________ Func-list mailing list Func-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/func-list