--************************************************************************************************ -- script : UMP failover -- author : Nimsoft (Rowan Collis) - June 2012 -- version: 1.0 -- desc : this script should run on the secondary nas which is also running the HA probe. -- When the HA probe detects a failover, an alarm is raised which triggers this script --************************************************************************************************ -- Version | Details --************************************************************************************************ -- 1.0 | Initial Version --************************************************************************************************ --************************************************************************************************ --Setup alarm to initiate failover --The driving nas profile needs to pick up only two HA alarms ie the "initiating failover" --and "stopping failover" . Use "on message arrival" and Probe = HA and message = /.*failover.*/ --and nms robot name = robotname (of where HA probe is running) --************************************************************************************************ a=alarm.get () split = split(a.message) message1 = split[1].." "..split[2] print(message1) ------------------------------------- -- OVERRIDES FOR TESTING ------------------------------------- --message1 = "Initiating failover" --message1 = "Stopping failover," ------------------------------------- --************************************************************************************************ -- Setup UMP robots (maybe more than one) and Primary and Secondary hubs -- (If your UMP robots are attached to the hub which has just gone down -- then you have to assume that they're jumping to their secondary --************************************************************************************************ PriHubAddr = "/London2012/pdc-l1monms-001/" SecHubAddr = "/London2012/pdc-l1monms-002/" PriHub = "pdc-l1monms-001" SecHub = "pdc-l1monms-002" umpname = {"pdc-l1monws-001","pdc-l1monws-002","pdc-l1monws-003","pdc-l1monws-004","pdc-l1monws-005",} if message1 == "Initiating failover" then mode = "FAILOVER" elseif message1 == "Stopping failover," then mode = "FAILBACK" else print("UMP Failover script Error - incorrect trigger alarm, check NAS profile") end --********************************************************************************************** -- function for UMP robots check - need to wait for the robots to failover before anything -- (presuming they are attached to primary and secondary hubs and not another hub) -- you might need to increase count to greater than 6 if your robot failover is a bit slow... --********************************************************************************************** function check_umprobot(hubaddr,ump) robotsup = false count=0 repeat res,rc = nimbus.request (hubaddr..ump.."/controller","get_info") if rc == 0 then robotsup = true print(hubaddr..ump.." has jumped, looped "..count.." times") else sleep (20000) count=count+1 end until robotsup or count==6 end --*********************************************************************************************** -- Reconfigure DAP function --*********************************************************************************************** function reconfigure_dap(hubaddr,hubname,ump) print("Reconfiguring DAP on "..ump) dappds = pds.create() pds.putString(dappds,"name","dap") pds.putString(dappds,"section","/setup") args = pds.create() pds.putString (args,"name","dap") cfg,rc = nimbus.request (hubaddr..ump.."/controller","probe_config_get",args) if rc == 0 then dap = cfg["/setup"] if dap ~= nil then printf("Changing data_engine from = %s",dap.data_engine) -- data engine pds.putString(dappds,"key","data_engine") pds.putString(dappds,"value",hubaddr..hubname.."/data_engine") result,rc = nimbus.request(hubaddr..ump.."/controller","probe_config_set",dappds) if rc ~= 0 then print("Nimbus Request Error - Probe Config Set for dap on "..hubaddr..ump.." (error "..rc..")") end -- check config is set cfg,rc = nimbus.request (hubaddr..ump.."/controller","probe_config_get",args) if rc == 0 then dap = cfg["/setup"] if dap ~= nil then printf("Changing data_engine to = %s",dap.data_engine) end else print("Nimbus Request Error2 - Probe Config Get for dap on "..hubaddr..ump.." (error "..rc..")") end -- restart dap result,rc = nimbus.request(hubaddr..ump.."/dap","_restart") if rc ~= 0 then print("Nimbus Request Error - Probe Restart for dap on "..hubaddr..ump.." (error "..rc..")") else print("DAP on "..hubaddr..ump.." restarted ") pds.delete(dappds) end else print("Missing Dap Config in setup section on "..hubaddr..ump) end else print("Nimbus Request Error1 - Probe Config Get for dap on "..hubaddr..ump.." (error "..rc..")") end end --*********************************************************************************************** -- Reconfigure Dashboard Engine function --*********************************************************************************************** function reconfigure_dashboard_engine(hubaddr,hubname,ump) print("Reconfiguring Dashboard Engine on "..hubaddr..ump) dashpds = pds.create() pds.putString(dashpds,"name","dashboard_engine") pds.putString(dashpds,"section","/nimbus") args = pds.create() pds.putString (args,"name","dashboard_engine") cfg,rc = nimbus.request (hubaddr..ump.."/controller","probe_config_get",args) if rc == 0 then dash = cfg["/nimbus"] if dash ~= nil then printf("Changing data_engine_address from = %s",dash.data_engine_address) printf("Changing nas from = %s",dash.nas_address) -- data engine pds.putString(dashpds,"key","data_engine_address") pds.putString(dashpds,"value",hubaddr..hubname.."/data_engine") result,rc = nimbus.request(hubaddr..ump.."/controller","probe_config_set",dashpds) if rc ~= 0 then print("Nimbus Request Error - Probe Config Set(data engine) for dashboard_engine on "..hubaddr..ump.." (error "..rc..")") end -- nas pds.putString(dashpds,"key","nas_address") pds.putString(dashpds,"value",hubaddr..hubname.."/nas") result,rc = nimbus.request(hubaddr..ump.."/controller","probe_config_set",dashpds) if rc ~= 0 then print("Nimbus Request Error - Probe Config Set(nas) for dashboard_engine on "..hubaddr..ump.." (error "..rc..")") end -- check config is set cfg,rc = nimbus.request (hubaddr..ump.."/controller","probe_config_get",args) if rc == 0 then dash = cfg["/nimbus"] if dash ~= nil then printf("Changing data_engine_address to = %s",dash.data_engine_address) printf("Changing nas to = %s",dash.nas_address) end else print("Nimbus Request Error2 - Probe Config Get for dashboard_engine on "..hubaddr..ump.." (error "..rc..")") end -- restart dashboard_engine result,rc = nimbus.request(hubaddr..ump.."/dashboard_engine","_restart") if rc ~= 0 then print("Nimbus Request Error - Probe Restart for dashboard_engine on "..hubaddr..ump.." (error "..rc..")") else print("Dashboard_Engine on "..hubaddr..ump.." restarted ") pds.delete(dashpds) end else print("Missing Dashboard Engine Config in nimbus section on"..hubaddr..ump) end else print("Nimbus Request Error1 - Probe Config Get for dashboard_engine on "..hubaddr..ump.." (error "..rc..")") end end --*********************************************************************************************** -- Reconfigure WASP function --*********************************************************************************************** function reconfigure_wasp(hubaddr,hubname,ump) print("Reconfiguring WASP on "..hubaddr..ump) wasppds = pds.create() pds.putString(wasppds,"name","wasp") args = pds.create() pds.putString (args,"name","wasp") cfg,rc = nimbus.request (hubaddr..ump.."/controller","probe_config_get",args) if rc == 0 then waspsetup = cfg["/setup"] if waspsetup ~= nil then printf("Changing data_engine from = %s",waspsetup.data_engine) -- printf("Changing discovery_server from = %s",waspsetup.discovery_server) -- printf("Changing dashboard_engine from = %s",waspsetup.dashboard_engine) -- data engine pds.putString(wasppds,"section","/setup") pds.putString(wasppds,"key","data_engine") pds.putString(wasppds,"value",hubaddr..hubname.."/data_engine") result,rc = nimbus.request(hubaddr..ump.."/controller","probe_config_set",wasppds) if rc ~= 0 then print("Nimbus Request Error - Probe Config Set(data engine) for wasp on "..hubaddr..ump.." (error "..rc..")") end --discovery server -- pds.putString(wasppds,"key","discovery_server") -- pds.putString(wasppds,"value",hubaddr.."/discovery_server") -- result,rc = nimbus.request(hubaddr..ump.."/controller","probe_config_set",wasppds) -- if rc ~= 0 then -- print("Nimbus Request wasp disco (error "..rc..")") -- end --dashboard engine -local -- pds.putString(wasppds,"key","dashboard_engine") -- pds.putString(wasppds,"value","dashboard_engine") -- result,rc = nimbus.request(hubaddr..ump.."/controller","probe_config_set",wasppds) -- if rc ~= 0 then -- print("Nimbus Request wasp dash (error "..rc..")") -- end else print("Missing Wasp Config in Setup section on"..hubaddr..ump) end waspcommon = cfg["/ump_common"] if waspcommon ~= nil then printf("Changing nas from = %s",waspcommon.nas) printf("Changing sla_engine from = %s",waspcommon.sla_engine) printf("Changing ace from = %s",waspcommon.ace) printf("Changing nis_server from = %s",waspcommon.nis_server) -- nas pds.putString(wasppds,"section","/ump_common") pds.putString(wasppds,"key","nas") pds.putString(wasppds,"value",hubaddr..hubname.."/nas") result,rc = nimbus.request(hubaddr..ump.."/controller","probe_config_set",wasppds) if rc ~= 0 then print("Nimbus Request Error - Probe Config Set(nas) for wasp on "..hubaddr..ump.." (error "..rc..")") end -- sla_engine pds.putString(wasppds,"section","/ump_common") pds.putString(wasppds,"key","sla_engine") pds.putString(wasppds,"value",hubaddr..hubname.."/sla_engine") result,rc = nimbus.request(hubaddr..ump.."/controller","probe_config_set",wasppds) if rc ~= 0 then print("Nimbus Request Error - Probe Config Set(sla_engine) for wasp on "..hubaddr..ump.." (error "..rc..")") end -- ace pds.putString(wasppds,"section","/ump_common") pds.putString(wasppds,"key","ace") pds.putString(wasppds,"value",hubaddr..hubname.."/ace") result,rc = nimbus.request(hubaddr..ump.."/controller","probe_config_set",wasppds) if rc ~= 0 then print("Nimbus Request Error - Probe Config Set(ace) for wasp on "..hubaddr..ump.." (error "..rc..")") end -- nis_server pds.putString(wasppds,"section","/ump_common") pds.putString(wasppds,"key","nis_server") pds.putString(wasppds,"value",hubaddr..hubname.."/nis_server") result,rc = nimbus.request(hubaddr..ump.."/controller","probe_config_set",wasppds) if rc ~= 0 then print("Nimbus Request Error - Probe Config Set(nis_server) for wasp on "..hubaddr..ump.." (error "..rc..")") end else print("Missing Wasp Config in UMP_common section on"..hubaddr..ump) end -- check config is set cfg,rc = nimbus.request (hubaddr..ump.."/controller","probe_config_get",args) if rc == 0 then waspcommon = cfg["/ump_common"] if waspcommon ~= nil then printf("Changing nas to = %s",waspcommon.nas) printf("Changing sla_engine to = %s",waspcommon.sla_engine) printf("Changing ace to = %s",waspcommon.ace) printf("Changing nis_server to = %s",waspcommon.nis_server) else print("Missing Wasp Config2 in UMP_common section on"..hubaddr..ump) end else print("Nimbus Request Error2 - Probe Config Get for wasp on "..hubaddr..ump.." (error "..rc..")") end -- Alarm Console Custom NAS waspcustomac = cfg["/webapps/alarmconsole/custom/uncrypted"] if waspcustomac ~= nil then printf("Changing AC nas from = %s",waspcustomac.nas) pds.putString(wasppds,"section","/webapps/alarmconsole/custom/uncrypted") pds.putString(wasppds,"key","nas") pds.putString(wasppds,"value",hubaddr..hubname.."/nas") result,rc = nimbus.request(hubaddr..ump.."/controller","probe_config_set",wasppds) if rc ~= 0 then print("Nimbus Request Error - Probe Config Set(AC custom) for wasp on "..hubaddr..ump.." (error "..rc..")") end else print("Missing Wasp Config in webapps/alarmconsole/custom/uncrypted section on"..hubaddr..ump) end -- Custom Dashboards Custom NAS waspcustomdash = cfg["/webapps/customdashboards/custom/uncrypted"] if waspcustomdash ~= nil then printf("Changing CD nas from = %s",waspcustomdash.nas) pds.putString(wasppds,"section","/webapps/customdashboards/custom/uncrypted") pds.putString(wasppds,"key","nas") pds.putString(wasppds,"value",hubaddr..hubname.."/nas") result,rc = nimbus.request(hubaddr..ump.."/controller","probe_config_set",wasppds) if rc ~= 0 then print("Nimbus Request Error - Probe Config Set(CD custom) for wasp on "..hubaddr..ump.." (error "..rc..")") end else print("Missing Wasp Config in webapps/customdashboards/custom/uncrypted section on"..hubaddr..ump) end -- Dynamic Views Custom NAS waspcustomdv = cfg["/webapps/dynamicviews/custom/uncrypted"] if waspcustomdv ~= nil then printf("Changing DV nas from = %s",waspcustomdv.nas) pds.putString(wasppds,"section","/webapps/dynamicviews/custom/uncrypted") pds.putString(wasppds,"key","nas") pds.putString(wasppds,"value",hubaddr..hubname.."/nas") result,rc = nimbus.request(hubaddr..ump.."/controller","probe_config_set",wasppds) if rc ~= 0 then print("Nimbus Request Error - Probe Config Set(DV custom) for wasp on "..hubaddr..ump.." (error "..rc..")") end else print("Missing Wasp Config in webapps/dynamicviews/custom/uncrypted section on"..hubaddr..ump) end -- Dashboard Designer Custom DAP waspcustomdd = cfg["/webapps/dashboarddesigner/custom/uncrypted"] if waspcustomdd ~= nil then printf("Changing DD Dap from = %s",waspcustomdd.dap) pds.putString(wasppds,"section","/webapps/dashboarddesigner/custom/uncrypted") pds.putString(wasppds,"key","dap") pds.putString(wasppds,"value","dap") result,rc = nimbus.request(hubaddr..ump.."/controller","probe_config_set",wasppds) if rc ~= 0 then print("Nimbus Request Error - Probe Config Set(DD custom) for wasp on "..hubaddr..ump.." (error "..rc..")") end else print("Missing Wasp Config in webapps/dashboarddesigner/custom/uncrypted section on"..hubaddr..ump) end -- restart wasp result,rc = nimbus.request(hubaddr..ump.."/wasp","_restart") if rc ~= 0 then print("Nimbus Request Error - Probe Restart for wasp on "..hubaddr..ump.." (error "..rc..")") else print("WASP on "..hubaddr..ump.." restarted ") pds.delete(wasppds) end else print("Nimbus Request Error1 - Probe Config Get for wasp on "..hubaddr..ump.." (error "..rc..")") end end --************************************************************************************************ -- Main section --************************************************************************************************ if mode == "FAILOVER" then for _,ump in pairs (umpname) do check_umprobot(SecHubAddr,ump) reconfigure_dap(SecHubAddr,SecHub,ump) reconfigure_dashboard_engine(SecHubAddr,SecHub,ump) reconfigure_wasp(SecHubAddr,SecHub,ump) end elseif mode == "FAILBACK" then for _,ump in pairs (umpname) do check_umprobot(PriHubAddr,ump) reconfigure_dap(PriHubAddr,PriHub,ump) reconfigure_dashboard_engine(PriHubAddr,PriHub,ump) reconfigure_wasp(PriHubAddr,PriHub,ump) end end --************************************************************************************************ -- Failover complete --************************************************************************************************ if mode ~= nil then print("UMP "..mode.." COMPLETED") else print(" UMP_FAILOVER script failed ") end