Skip to content

Commit 63e839c

Browse files
Jayapalchaturvedia
authored andcommitted
CLOUDSTACK-5966 Added enable/disable monitoring service in global config
(cherry picked from commit 782265e) Signed-off-by: Animesh Chaturvedi <animesh@apache.org>
1 parent 3fa300b commit 63e839c

8 files changed

Lines changed: 60 additions & 7 deletions

File tree

‎core/src/com/cloud/agent/api/routing/NetworkElementCommand.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public abstract class NetworkElementCommand extends Command {
3434
public static final String GUEST_BRIDGE = "guest.bridge";
3535
public static final String VPC_PRIVATE_GATEWAY = "vpc.gateway.private";
3636
public static final String FIREWALL_EGRESS_DEFAULT = "firewall.egress.default";
37+
public static final String ROUTER_MONITORING_DISABLE = "router.monitor.disable";
38+
3739

3840

3941
protected NetworkElementCommand() {

‎core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,9 +821,12 @@ private Answer executeProxyLoadScan(final Command cmd, final long proxyVmId, fin
821821
return new ConsoleProxyLoadAnswer(cmd, proxyVmId, proxyVmName, success, result);
822822
}
823823

824-
public String configureMonitor(final String routerIP, final String config) {
824+
public String configureMonitor(final String routerIP, final String config, final String disable) {
825825

826826
String args= " -c " + config;
827+
if (disable != null) {
828+
args = args + "-d";
829+
}
827830
return routerProxy("monitor_service.sh", routerIP, args);
828831
}
829832

@@ -968,9 +971,11 @@ private SetStaticRouteAnswer execute(SetStaticRouteCommand cmd) {
968971
private Answer execute(SetMonitorServiceCommand cmd) {
969972

970973
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
974+
String disable = cmd.getAccessDetail(NetworkElementCommand.ROUTER_MONITORING_DISABLE);
971975
String config = cmd.getConfiguration();
972976

973-
String result = configureMonitor(routerIp, config);
977+
978+
String result = configureMonitor(routerIp, config, disable);
974979

975980
if (result != null) {
976981
return new Answer(cmd, false, "SetMonitorServiceCommand failed");

‎plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,10 +806,14 @@ protected Answer execute(SetMonitorServiceCommand cmd) {
806806

807807
String controlIp = getRouterSshControlIp(cmd);
808808
String config = cmd.getConfiguration();
809+
String disable = cmd.getAccessDetail(NetworkElementCommand.ROUTER_MONITORING_DISABLE);
809810

810811
String args = "";
811812

812813
args += " -c " + config;
814+
if (disable != null) {
815+
args = args + " -d ";
816+
}
813817

814818
try {
815819
VmwareManager mgr = getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7585,13 +7585,18 @@ private Answer execute(SetMonitorServiceCommand cmd) {
75857585

75867586
Connection conn = getConnection();
75877587
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
7588+
String disable = cmd.getAccessDetail(NetworkElementCommand.ROUTER_MONITORING_DISABLE);
75887589

75897590
if (routerIp == null) {
75907591
return new Answer(cmd);
75917592
}
75927593

75937594
String args = "monitor_service.sh " + routerIp;
75947595
args += " -c " + config;
7596+
if (disable != null) {
7597+
args += " -d ";
7598+
}
7599+
75957600

75967601
String result = callHostPlugin(conn, "vmops", "routerProxy", "args", args);
75977602
if (result == null || result.isEmpty()) {

‎server/src/com/cloud/configuration/Config.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public enum Config {
105105
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),
106106

107107
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),
108+
EnableServiceMonitoring("Network", ManagementServer.class, Boolean.class, "network.router.enableserviceMonitoring", "false", "service monitoring in router enable/disable option, default false", null),
108109

109110
//VPN
110111
RemoteAccessVpnPskLength("Network", AgentManager.class, Integer.class, "remote.access.vpn.psk.length", "24", "The length of the ipsec preshared key (minimum 8, maximum 256)", null),

‎server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,12 +2223,20 @@ public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile prof
22232223

22242224
finalizeUserDataAndDhcpOnStart(cmds, router, provider, guestNetworkId);
22252225
}
2226-
finalizeMonitorServiceOnStrat(cmds, profile, router, provider, routerGuestNtwkIds.get(0));
2226+
2227+
String serviceMonitringSet = _configDao.getValue(Config.EnableServiceMonitoring.key());
2228+
2229+
if (serviceMonitringSet != null && serviceMonitringSet.equalsIgnoreCase("true")) {
2230+
finalizeMonitorServiceOnStrat(cmds, profile, router, provider, routerGuestNtwkIds.get(0), true);
2231+
} else {
2232+
finalizeMonitorServiceOnStrat(cmds, profile, router, provider, routerGuestNtwkIds.get(0), false);
2233+
}
2234+
22272235

22282236
return true;
22292237
}
22302238

2231-
private void finalizeMonitorServiceOnStrat(Commands cmds, VirtualMachineProfile profile, DomainRouterVO router, Provider provider, long networkId) {
2239+
private void finalizeMonitorServiceOnStrat(Commands cmds, VirtualMachineProfile profile, DomainRouterVO router, Provider provider, long networkId, Boolean add) {
22322240

22332241
NetworkVO network = _networkDao.findById(networkId);
22342242

@@ -2270,6 +2278,10 @@ private void finalizeMonitorServiceOnStrat(Commands cmds, VirtualMachineProfile
22702278
command.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(networkId, router.getId()));
22712279
command.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
22722280

2281+
if (!add) {
2282+
command.setAccessDetail(NetworkElementCommand.ROUTER_MONITORING_DISABLE, add.toString());
2283+
}
2284+
22732285
cmds.addCommand("monitor", command);
22742286
}
22752287

‎setup/db/db/schema-421to430.sql‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,4 +1089,5 @@ CREATE VIEW `cloud`.`user_vm_view` AS
10891089
left join
10901090
`cloud`.`user_vm_details` `custom_ram_size` ON (((`custom_ram_size`.`vm_id` = `cloud`.`vm_instance`.`id`) and (`custom_ram_size`.`name` = 'memory')));
10911091

1092+
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';
10921093

‎systemvm/patches/debian/config/opt/cloud/bin/monitor_service.sh‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ then
2525
exit 1
2626
fi
2727

28-
set -x
28+
#set -x
2929
usage() {
3030
printf "Usage: %s: -c config string \n" $(basename $0) >&2
3131
}
@@ -58,13 +58,36 @@ done
5858

5959
config=$2
6060

61+
if [ -n "$3" ]
62+
then
6163
#delete cron job before updating config file
62-
crontab -l | grep -v monitorServices.py | crontab -
64+
crontab -l|grep "monitorServices.py"
65+
66+
if [ $? -eq 0 ]
67+
then
68+
t=`date +%s`;
69+
touch /tmp/monitor-$t.txt;
70+
conf=/tmp/monitor-$t.txt
71+
crontab -l >$conf
72+
sed -i /#monitoringConfig/,+3d $conf
73+
crontab $conf
74+
rm $conf
75+
fi
76+
77+
78+
logger -t cloud "deleted crontab entry for monitoring services"
79+
unlock_exit 0 $lock $locked
80+
fi
6381

6482
create_config $config
6583

6684
#add cron job
67-
(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 -
85+
crontab -l|grep "monitorServices.py"
86+
if [ $? -ne 0 ]
87+
then
88+
(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 -
89+
logger -t cloud "added crontab entry for monitoring services"
90+
fi
6891

6992

7093
unlock_exit 0 $lock $locked

0 commit comments

Comments
 (0)