CLOUDSTACK-5966 Added enable/disable monitoring service in global config

(cherry picked from commit 782265e713)

Signed-off-by: Animesh Chaturvedi <animesh@apache.org>
This commit is contained in:
Jayapal 2014-01-28 19:20:44 +05:30 committed by Animesh Chaturvedi
parent 3fa300b132
commit 63e839c0f8
8 changed files with 60 additions and 7 deletions

View File

@ -34,6 +34,8 @@ public abstract class NetworkElementCommand extends Command {
public static final String GUEST_BRIDGE = "guest.bridge";
public static final String VPC_PRIVATE_GATEWAY = "vpc.gateway.private";
public static final String FIREWALL_EGRESS_DEFAULT = "firewall.egress.default";
public static final String ROUTER_MONITORING_DISABLE = "router.monitor.disable";
protected NetworkElementCommand() {

View File

@ -821,9 +821,12 @@ public class VirtualRoutingResource implements Manager {
return new ConsoleProxyLoadAnswer(cmd, proxyVmId, proxyVmName, success, result);
}
public String configureMonitor(final String routerIP, final String config) {
public String configureMonitor(final String routerIP, final String config, final String disable) {
String args= " -c " + config;
if (disable != null) {
args = args + "-d";
}
return routerProxy("monitor_service.sh", routerIP, args);
}
@ -968,9 +971,11 @@ public class VirtualRoutingResource implements Manager {
private Answer execute(SetMonitorServiceCommand cmd) {
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
String disable = cmd.getAccessDetail(NetworkElementCommand.ROUTER_MONITORING_DISABLE);
String config = cmd.getConfiguration();
String result = configureMonitor(routerIp, config);
String result = configureMonitor(routerIp, config, disable);
if (result != null) {
return new Answer(cmd, false, "SetMonitorServiceCommand failed");

View File

@ -806,10 +806,14 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
String controlIp = getRouterSshControlIp(cmd);
String config = cmd.getConfiguration();
String disable = cmd.getAccessDetail(NetworkElementCommand.ROUTER_MONITORING_DISABLE);
String args = "";
args += " -c " + config;
if (disable != null) {
args = args + " -d ";
}
try {
VmwareManager mgr = getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);

View File

@ -7585,6 +7585,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
Connection conn = getConnection();
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
String disable = cmd.getAccessDetail(NetworkElementCommand.ROUTER_MONITORING_DISABLE);
if (routerIp == null) {
return new Answer(cmd);
@ -7592,6 +7593,10 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
String args = "monitor_service.sh " + routerIp;
args += " -c " + config;
if (disable != null) {
args += " -d ";
}
String result = callHostPlugin(conn, "vmops", "routerProxy", "args", args);
if (result == null || result.isEmpty()) {

View File

@ -105,6 +105,7 @@ public enum Config {
SecurityGroupDefaultAdding("Network", ManagementServer.class, Boolean.class, "network.securitygroups.defaultadding", "true", "If true, the user VM would be added to the default security group by default", null),
GuestOSNeedGatewayOnNonDefaultNetwork("Network", NetworkOrchestrationService.class, String.class, "network.dhcp.nondefaultnetwork.setgateway.guestos", "Windows", "The guest OS's name start with this fields would result in DHCP server response gateway information even when the network it's on is not default network. Names are separated by comma.", null),
EnableServiceMonitoring("Network", ManagementServer.class, Boolean.class, "network.router.enableserviceMonitoring", "false", "service monitoring in router enable/disable option, default false", null),
//VPN
RemoteAccessVpnPskLength("Network", AgentManager.class, Integer.class, "remote.access.vpn.psk.length", "24", "The length of the ipsec preshared key (minimum 8, maximum 256)", null),

View File

@ -2223,12 +2223,20 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
finalizeUserDataAndDhcpOnStart(cmds, router, provider, guestNetworkId);
}
finalizeMonitorServiceOnStrat(cmds, profile, router, provider, routerGuestNtwkIds.get(0));
String serviceMonitringSet = _configDao.getValue(Config.EnableServiceMonitoring.key());
if (serviceMonitringSet != null && serviceMonitringSet.equalsIgnoreCase("true")) {
finalizeMonitorServiceOnStrat(cmds, profile, router, provider, routerGuestNtwkIds.get(0), true);
} else {
finalizeMonitorServiceOnStrat(cmds, profile, router, provider, routerGuestNtwkIds.get(0), false);
}
return true;
}
private void finalizeMonitorServiceOnStrat(Commands cmds, VirtualMachineProfile profile, DomainRouterVO router, Provider provider, long networkId) {
private void finalizeMonitorServiceOnStrat(Commands cmds, VirtualMachineProfile profile, DomainRouterVO router, Provider provider, long networkId, Boolean add) {
NetworkVO network = _networkDao.findById(networkId);
@ -2270,6 +2278,10 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
command.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(networkId, router.getId()));
command.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
if (!add) {
command.setAccessDetail(NetworkElementCommand.ROUTER_MONITORING_DISABLE, add.toString());
}
cmds.addCommand("monitor", command);
}

View File

@ -1089,4 +1089,5 @@ CREATE VIEW `cloud`.`user_vm_view` AS
left join
`cloud`.`user_vm_details` `custom_ram_size` ON (((`custom_ram_size`.`vm_id` = `cloud`.`vm_instance`.`id`) and (`custom_ram_size`.`name` = 'memory')));
INSERT INTO `cloud`.`configuration`(category, instance, component, name, value, description, default_value) VALUES ('NetworkManager', 'DEFAULT', 'management-server', 'network.router.EnableServiceMonitoring', 'false', 'service monitoring in router enable/disable option, default false', 'false') ON DUPLICATE KEY UPDATE category='NetworkManager';

View File

@ -25,7 +25,7 @@ then
exit 1
fi
set -x
#set -x
usage() {
printf "Usage: %s: -c config string \n" $(basename $0) >&2
}
@ -58,13 +58,36 @@ done
config=$2
if [ -n "$3" ]
then
#delete cron job before updating config file
crontab -l | grep -v monitorServices.py | crontab -
crontab -l|grep "monitorServices.py"
if [ $? -eq 0 ]
then
t=`date +%s`;
touch /tmp/monitor-$t.txt;
conf=/tmp/monitor-$t.txt
crontab -l >$conf
sed -i /#monitoringConfig/,+3d $conf
crontab $conf
rm $conf
fi
logger -t cloud "deleted crontab entry for monitoring services"
unlock_exit 0 $lock $locked
fi
create_config $config
#add cron job
(crontab -l ;echo -e "SHELL=/bin/bash\nPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\n */3 * * * * /usr/bin/python /root/monitorServices.py") | crontab -
crontab -l|grep "monitorServices.py"
if [ $? -ne 0 ]
then
(crontab -l ;echo -e "#monitoringConfig\nSHELL=/bin/bash\nPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\n */3 * * * * /usr/bin/python /root/monitorServices.py") | crontab -
logger -t cloud "added crontab entry for monitoring services"
fi
unlock_exit 0 $lock $locked