Subversion Repositories SmartDukaan

Rev

Rev 23755 | Rev 24121 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 23755 Rev 23794
Line 1... Line 1...
1
package com.smartdukaan.cron.monitored;
1
package com.smartdukaan.cron.monitored;
2
 
2
 
-
 
3
import java.io.File;
-
 
4
import java.io.IOException;
3
import java.util.HashMap;
5
import java.util.HashMap;
-
 
6
import java.util.LinkedHashMap;
4
import java.util.Map;
7
import java.util.Map;
5
 
8
 
6
import org.apache.logging.log4j.LogManager;
9
import org.apache.logging.log4j.LogManager;
7
import org.apache.logging.log4j.Logger;
10
import org.apache.logging.log4j.Logger;
8
import org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.beans.factory.annotation.Autowired;
-
 
12
import org.springframework.beans.factory.annotation.Value;
9
import org.springframework.stereotype.Component;
13
import org.springframework.stereotype.Component;
10
 
14
 
-
 
15
import com.smartdukaan.cron.properties.WriteToPropertiesFile;
-
 
16
import com.spice.profitmandi.common.enumuration.ProviderBalanceFrom;
11
import com.spice.profitmandi.common.enumuration.SchemeType;
17
import com.spice.profitmandi.common.enumuration.SchemeType;
-
 
18
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
-
 
19
import com.spice.profitmandi.common.model.ProfitMandiConstants;
-
 
20
import com.spice.profitmandi.common.model.RechargeCredential;
12
import com.spice.profitmandi.common.web.client.RestClient;
21
import com.spice.profitmandi.common.web.client.RestClient;
13
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
22
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
-
 
23
import com.spice.profitmandi.service.recharge.RechargeService;
-
 
24
import com.spice.profitmandi.service.recharge.provider.OxigenRechargeProviderService;
-
 
25
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
14
 
26
 
15
@Component
27
@Component
16
public class NagiosMonitorTasks {
28
public class NagiosMonitorTasks {
17
 
29
 
18
	private static final Logger log = LogManager.getLogger(NagiosMonitorTasks.class);
30
	private static final Logger log = LogManager.getLogger(NagiosMonitorTasks.class);
19
 
31
 
-
 
32
	@Value("${oxigen.recharge.transaction.url}")
-
 
33
	private String oxigenRechargeTransactionUrl;
-
 
34
 
-
 
35
	@Value("${oxigen.recharge.enquiry.url}")
-
 
36
	private String oxigenRechargeEnquiryUrl;
-
 
37
 
-
 
38
	@Value("${oxigen.recharge.auth.key}")
-
 
39
	private String oxigenRechargeAuthKey;
-
 
40
 
-
 
41
	@Value("${oxigen.recharge.validation.url}")
-
 
42
	private String oxigenRechargeValidationUrl;
-
 
43
 
-
 
44
	@Value("${oxigen.recharge.validation.auth.key}")
-
 
45
	private String oxigenRechargeValidationAuthKey;
-
 
46
 
-
 
47
	@Value("${think.walnut.digital.recharge.transaction.mobile.url}")
-
 
48
	private String thinkWalnutDigitalRechargeTransactionMobileUrl;
-
 
49
 
-
 
50
	@Value("${think.walnut.digital.recharge.transaction.dth.url}")
-
 
51
	private String thinkWalnutDigitalRechargeTransactionDthUrl;
-
 
52
 
-
 
53
	@Value("${think.walnut.digital.recharge.enquiry.url}")
-
 
54
	private String thinkWalnutDigitalRechargeEnquiryUrl;
-
 
55
 
-
 
56
	@Value("${think.walnut.digital.recharge.balance.url}")
-
 
57
	private String thinkWalnutDigitalRechargeBalanceUrl;
-
 
58
 
-
 
59
	@Value("${think.walnut.digital.recharge.username}")
-
 
60
	private String thinkWalnutDigitalRechargeUserName;
-
 
61
 
-
 
62
	@Value("${think.walnut.digital.recharge.password}")
-
 
63
	private String thinkWalnutDigitalRechargePassword;
-
 
64
 
-
 
65
	@Value("${think.walnut.digital.recharge.auth.key}")
-
 
66
	private String thinkWalnutDigitalRechargeAuthKey;
-
 
67
 
-
 
68
	
20
	@Autowired
69
	@Autowired
21
	private RestClient restClient;
70
	private OxigenRechargeProviderService oxigenRechargeProviderService;
22
	
71
	
23
	@Autowired
72
	@Autowired
-
 
73
	private ThinkWalnutDigitalRechargeProviderService thinkWalnutDigitalRechargeProviderService;
-
 
74
	
-
 
75
	@Autowired
-
 
76
	private RestClient restClient;
-
 
77
 
-
 
78
	@Autowired
24
	ItemRepository itemRepository;
79
	ItemRepository itemRepository;
-
 
80
	
-
 
81
	@Autowired
-
 
82
	private RechargeService rechargeService;
25
 
83
 
-
 
84
	@Autowired
-
 
85
	private WriteToPropertiesFile writeToPropertiesFile;
-
 
86
	
-
 
87
	String nagiosPropertiesFile="/var/log/services/nagios-Monitoring.properties";
-
 
88
 
-
 
89
	
26
	public void reportSmsCount() throws Throwable {
90
	public void reportSmsCount() throws Throwable {
27
		String htmlpage;
91
		String htmlpage;
28
		int currentBalance = 0;
92
		int currentSmsCount = 0;
-
 
93
		LinkedHashMap<String,String> propertiesDetails = new LinkedHashMap<>();
29
		String uri = "/MessagingGateway/LoginAction";
94
		String uri = "/MessagingGateway/LoginAction";
30
		Map<String, String> params = new HashMap<>();
95
		Map<String, String> params = new HashMap<>();
31
		params.put("user", "srlsaholic");
96
		params.put("user", "srlsaholic");
32
		params.put("password", "sr18mar");
97
		params.put("password", "sr18mar");
33
		String response = restClient.post(SchemeType.HTTP, "103.15.179.45", 8085, uri, params, new HashMap<>());
98
		String response = restClient.post(SchemeType.HTTP, "103.15.179.45", 8085, uri, params, new HashMap<>());
Line 37... Line 102...
37
					(response.substring(response.indexOf("Current Balance"), response.indexOf("</div>")).indexOf(">"))
102
					(response.substring(response.indexOf("Current Balance"), response.indexOf("</div>")).indexOf(">"))
38
							+ 1,
103
							+ 1,
39
					response.substring(response.indexOf("Current Balance"), response.indexOf("</div>")).length())
104
					response.substring(response.indexOf("Current Balance"), response.indexOf("</div>")).length())
40
					.trim();
105
					.trim();
41
			/// System.out.println(htmlpage);
106
			/// System.out.println(htmlpage);
42
			currentBalance = Integer.parseInt(htmlpage);
107
			currentSmsCount = Integer.parseInt(htmlpage);
43
			log.info("Got successfully parsed {}", currentBalance);
108
			log.info("Got successfully parsed {}", currentSmsCount);
-
 
109
			propertiesDetails.put("currentSmsCount",Integer.toString(currentSmsCount));
-
 
110
			writeToPropertiesFile.saveParamChanges(propertiesDetails,nagiosPropertiesFile);
-
 
111
			
-
 
112
			
44
		}
113
		}
-
 
114
		
-
 
115
	}
-
 
116
	
-
 
117
	public void currentOxygenBalance() throws ProfitMandiBusinessException, IOException
-
 
118
	{
-
 
119
		LinkedHashMap<String,String> propertiesDetails = new LinkedHashMap<>();
-
 
120
		float oxygenBalance =oxigenRechargeProviderService.doCheckBalanceRequest(oxigenRechargeTransactionUrl, oxigenRechargeAuthKey);
-
 
121
		log.info("Got oxygenBalance successfully parsed {}",oxygenBalance);
-
 
122
		propertiesDetails.put("oxigenBalance",Float.toString(oxygenBalance));
-
 
123
		writeToPropertiesFile.saveParamChanges(propertiesDetails,nagiosPropertiesFile);
-
 
124
		 
-
 
125
		
-
 
126
	}
-
 
127
	public void currentThinkWalnutBalace() throws ProfitMandiBusinessException, IOException
-
 
128
	{
-
 
129
		LinkedHashMap<String,String> propertiesDetails = new LinkedHashMap<>();
-
 
130
		RechargeCredential thinkWalnutDigitalRechargeCredential = new RechargeCredential();
-
 
131
		thinkWalnutDigitalRechargeCredential.setRechargeUrl(thinkWalnutDigitalRechargeBalanceUrl);
-
 
132
		thinkWalnutDigitalRechargeCredential.setRechargeUserName(thinkWalnutDigitalRechargeUserName);
-
 
133
		thinkWalnutDigitalRechargeCredential.setRechargePassword(thinkWalnutDigitalRechargePassword);
-
 
134
		thinkWalnutDigitalRechargeCredential.setRechargeAuthKey(thinkWalnutDigitalRechargeAuthKey);
-
 
135
		float thinkWalnutBalance=thinkWalnutDigitalRechargeProviderService.doCheckBalanceRequest(thinkWalnutDigitalRechargeCredential);
-
 
136
		log.info("ThinkWalnut Balance {}",thinkWalnutBalance);
-
 
137
		propertiesDetails.put("thinkWalnutBalance", Float.toString(thinkWalnutBalance));
-
 
138
		writeToPropertiesFile.saveParamChanges(propertiesDetails,nagiosPropertiesFile);
-
 
139
		
45
	}
140
	}
46
}
141
}
47
142