| 23724 |
amit.gupta |
1 |
package com.smartdukaan.cron.monitored;
|
| 23723 |
amit.gupta |
2 |
|
| 23794 |
govind |
3 |
import java.io.File;
|
|
|
4 |
import java.io.IOException;
|
| 23723 |
amit.gupta |
5 |
import java.util.HashMap;
|
| 23794 |
govind |
6 |
import java.util.LinkedHashMap;
|
| 23723 |
amit.gupta |
7 |
import java.util.Map;
|
|
|
8 |
|
| 23755 |
amit.gupta |
9 |
import org.apache.logging.log4j.LogManager;
|
|
|
10 |
import org.apache.logging.log4j.Logger;
|
| 23723 |
amit.gupta |
11 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23794 |
govind |
12 |
import org.springframework.beans.factory.annotation.Value;
|
| 23723 |
amit.gupta |
13 |
import org.springframework.stereotype.Component;
|
|
|
14 |
|
| 23794 |
govind |
15 |
import com.smartdukaan.cron.properties.WriteToPropertiesFile;
|
|
|
16 |
import com.spice.profitmandi.common.enumuration.ProviderBalanceFrom;
|
| 23723 |
amit.gupta |
17 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
| 23794 |
govind |
18 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
19 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
20 |
import com.spice.profitmandi.common.model.RechargeCredential;
|
| 23723 |
amit.gupta |
21 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 23731 |
amit.gupta |
22 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 23794 |
govind |
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;
|
| 23723 |
amit.gupta |
26 |
|
|
|
27 |
@Component
|
|
|
28 |
public class NagiosMonitorTasks {
|
|
|
29 |
|
| 23755 |
amit.gupta |
30 |
private static final Logger log = LogManager.getLogger(NagiosMonitorTasks.class);
|
| 23723 |
amit.gupta |
31 |
|
| 23794 |
govind |
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 |
|
| 23723 |
amit.gupta |
68 |
@Autowired
|
| 23794 |
govind |
69 |
private OxigenRechargeProviderService oxigenRechargeProviderService;
|
| 24121 |
govind |
70 |
|
| 23794 |
govind |
71 |
@Autowired
|
|
|
72 |
private ThinkWalnutDigitalRechargeProviderService thinkWalnutDigitalRechargeProviderService;
|
| 24121 |
govind |
73 |
|
| 23794 |
govind |
74 |
@Autowired
|
| 23723 |
amit.gupta |
75 |
private RestClient restClient;
|
| 23794 |
govind |
76 |
|
|
|
77 |
@Autowired
|
|
|
78 |
ItemRepository itemRepository;
|
| 24121 |
govind |
79 |
|
| 23731 |
amit.gupta |
80 |
@Autowired
|
| 23794 |
govind |
81 |
private RechargeService rechargeService;
|
| 23723 |
amit.gupta |
82 |
|
| 23794 |
govind |
83 |
@Autowired
|
|
|
84 |
private WriteToPropertiesFile writeToPropertiesFile;
|
|
|
85 |
|
| 24121 |
govind |
86 |
String nagiosPropertiesFile = "/var/log/services/nagios-Monitoring.properties";
|
|
|
87 |
|
| 23723 |
amit.gupta |
88 |
public void reportSmsCount() throws Throwable {
|
|
|
89 |
String htmlpage;
|
| 23794 |
govind |
90 |
int currentSmsCount = 0;
|
| 24121 |
govind |
91 |
LinkedHashMap<String, String> propertiesDetails = new LinkedHashMap<>();
|
| 24879 |
govind |
92 |
String uri = "/MessagingGateway/GetSMSBalance";
|
| 23723 |
amit.gupta |
93 |
Map<String, String> params = new HashMap<>();
|
| 24879 |
govind |
94 |
params.put("Username", "srlsaholic");
|
|
|
95 |
params.put("Password", "sr18mar");
|
| 23723 |
amit.gupta |
96 |
String response = restClient.post(SchemeType.HTTP, "103.15.179.45", 8085, uri, params, new HashMap<>());
|
|
|
97 |
// System.out.println("response Html"+response);
|
|
|
98 |
if (response.length() > 0) {
|
| 24879 |
govind |
99 |
htmlpage = response.substring(response.indexOf("=")+1);
|
|
|
100 |
System.out.println(htmlpage);
|
| 23794 |
govind |
101 |
currentSmsCount = Integer.parseInt(htmlpage);
|
|
|
102 |
log.info("Got successfully parsed {}", currentSmsCount);
|
| 24121 |
govind |
103 |
propertiesDetails.put("currentSmsCount", Integer.toString(currentSmsCount));
|
|
|
104 |
writeToPropertiesFile.saveParamChanges(propertiesDetails, nagiosPropertiesFile);
|
|
|
105 |
|
| 23723 |
amit.gupta |
106 |
}
|
| 24121 |
govind |
107 |
|
| 23723 |
amit.gupta |
108 |
}
|
| 24121 |
govind |
109 |
|
|
|
110 |
public void currentOxygenBalance() throws ProfitMandiBusinessException, IOException {
|
|
|
111 |
LinkedHashMap<String, String> propertiesDetails = new LinkedHashMap<>();
|
|
|
112 |
float oxygenBalance = oxigenRechargeProviderService.doCheckBalanceRequest(oxigenRechargeTransactionUrl,
|
|
|
113 |
oxigenRechargeAuthKey);
|
|
|
114 |
log.info("Got oxygenBalance successfully parsed {}", oxygenBalance);
|
|
|
115 |
propertiesDetails.put("oxigenBalance", Float.toString(oxygenBalance));
|
|
|
116 |
writeToPropertiesFile.saveParamChanges(propertiesDetails, nagiosPropertiesFile);
|
|
|
117 |
|
| 23794 |
govind |
118 |
}
|
| 24121 |
govind |
119 |
|
|
|
120 |
public void currentThinkWalnutBalace() throws ProfitMandiBusinessException, IOException {
|
|
|
121 |
LinkedHashMap<String, String> propertiesDetails = new LinkedHashMap<>();
|
| 23794 |
govind |
122 |
RechargeCredential thinkWalnutDigitalRechargeCredential = new RechargeCredential();
|
|
|
123 |
thinkWalnutDigitalRechargeCredential.setRechargeUrl(thinkWalnutDigitalRechargeBalanceUrl);
|
|
|
124 |
thinkWalnutDigitalRechargeCredential.setRechargeUserName(thinkWalnutDigitalRechargeUserName);
|
|
|
125 |
thinkWalnutDigitalRechargeCredential.setRechargePassword(thinkWalnutDigitalRechargePassword);
|
|
|
126 |
thinkWalnutDigitalRechargeCredential.setRechargeAuthKey(thinkWalnutDigitalRechargeAuthKey);
|
| 24121 |
govind |
127 |
float thinkWalnutBalance = thinkWalnutDigitalRechargeProviderService
|
|
|
128 |
.doCheckBalanceRequest(thinkWalnutDigitalRechargeCredential);
|
|
|
129 |
log.info("ThinkWalnut Balance {}", thinkWalnutBalance);
|
| 23794 |
govind |
130 |
propertiesDetails.put("thinkWalnutBalance", Float.toString(thinkWalnutBalance));
|
| 24121 |
govind |
131 |
writeToPropertiesFile.saveParamChanges(propertiesDetails, nagiosPropertiesFile);
|
|
|
132 |
|
| 23794 |
govind |
133 |
}
|
| 23723 |
amit.gupta |
134 |
}
|