#!/usr/bin/env python # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA # from kusu.core import rcplugin from kusu.core.db import KusuDB from primitive.system.software.dispatcher import Dispatcher import os import shutil global COMPONENT_NAME COMPONENT_NAME = "component-ganglia-server-v3_1_1" class KusuRC(rcplugin.Plugin): def __init__(self): rcplugin.Plugin.__init__(self) self.name = 'ganglia-config' self.desc = 'Setting up Ganglia' self.ngtypes = ['installer'] self.delete = True self.dbconn = KusuDB() self.dbconn.connect() def generateGangliaConfig(self): self.componentNodegroups = list(self.checkAvailableComponent()) for ng in self.componentNodegroups: # If ng is installer then don't copy make symlink only query = ('select ngid from nodegroups where ngname="%s"' % ng) self.dbconn.execute(query) ngid = self.dbconn.fetchone()[0] if ngid == 1: try: os.symlink("/etc/ganglia/gmond.conf", "/etc/cfm/%s/etc/ganglia/gmond.conf" % ng) except: pass else: shutil.copy("/etc/ganglia/gmond.conf", "/etc/cfm/%s/etc/ganglia" % ng) # Get the interfaces available for nodegroup query = ('select device from networks, nodegroups, ng_has_net ' 'WHERE networks.type="provision" AND ng_has_net.netid=networks.netid ' 'AND ng_has_net.ngid=nodegroups.ngid AND nodegroups.ngname="%s" ' 'AND NOT networks.device="bmc"' % ng) if ngid == 1: fptr = open("/etc/ganglia/gmond.conf", 'a') rfptr = open("/etc/ganglia/gmond.conf", 'r') else: fptr = open("/etc/cfm/%s/etc/ganglia/gmond.conf" % ng, 'a') rfptr = open("/etc/cfm/%s/etc/ganglia/gmond.conf" % ng, 'r') self.dbconn.execute(query) data = [] for dev in self.dbconn.fetchall(): flag = 0 mcastInfo = """ udp_send_channel { mcast_join = 239.2.11.71 port = 8649 ttl = 1 mcast_if = %s } udp_recv_channel { mcast_join = 239.2.11.71 port = 8649 bind = 239.2.11.71 mcast_if = %s } """ % (dev[0], dev[0]) # If the lines exist, don't write again data = rfptr.readlines() rfptr.seek(0,0) for line in data: if line.find(dev[0]) > 0: flag = 1 break if flag: continue else: fptr.writelines(mcastInfo) fptr.close() rfptr.close() def checkAvailableComponent(self): """ Return a list of all nodegroups that have the ganglia components in use """ items = [] query = ('select nodegroups.ngname from nodegroups, ng_has_comp, components where ' 'nodegroups.ngid = ng_has_comp.ngid and ng_has_comp.cid = components.cid and ' 'components.cname = "%s"' % COMPONENT_NAME) try: self.dbconn.execute(query) for item in self.dbconn.fetchall(): items.append(item[0]) return items except: return [] def run(self): self.generateGangliaConfig() return True if __name__ == "__main__": myApp = KusuRC() myApp.run()