Subversion Repositories SmartDukaan

Rev

Rev 23755 | Rev 24121 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
 
68
 
23723 amit.gupta 69
	@Autowired
23794 govind 70
	private OxigenRechargeProviderService oxigenRechargeProviderService;
71
 
72
	@Autowired
73
	private ThinkWalnutDigitalRechargeProviderService thinkWalnutDigitalRechargeProviderService;
74
 
75
	@Autowired
23723 amit.gupta 76
	private RestClient restClient;
23794 govind 77
 
78
	@Autowired
79
	ItemRepository itemRepository;
23731 amit.gupta 80
 
81
	@Autowired
23794 govind 82
	private RechargeService rechargeService;
23723 amit.gupta 83
 
23794 govind 84
	@Autowired
85
	private WriteToPropertiesFile writeToPropertiesFile;
86
 
87
	String nagiosPropertiesFile="/var/log/services/nagios-Monitoring.properties";
88
 
89
 
23723 amit.gupta 90
	public void reportSmsCount() throws Throwable {
91
		String htmlpage;
23794 govind 92
		int currentSmsCount = 0;
93
		LinkedHashMap<String,String> propertiesDetails = new LinkedHashMap<>();
23723 amit.gupta 94
		String uri = "/MessagingGateway/LoginAction";
95
		Map<String, String> params = new HashMap<>();
96
		params.put("user", "srlsaholic");
97
		params.put("password", "sr18mar");
98
		String response = restClient.post(SchemeType.HTTP, "103.15.179.45", 8085, uri, params, new HashMap<>());
99
		// System.out.println("response Html"+response);
100
		if (response.length() > 0) {
101
			htmlpage = response.substring(response.indexOf("Current Balance"), response.indexOf("</div>")).substring(
102
					(response.substring(response.indexOf("Current Balance"), response.indexOf("</div>")).indexOf(">"))
103
							+ 1,
104
					response.substring(response.indexOf("Current Balance"), response.indexOf("</div>")).length())
105
					.trim();
106
			/// System.out.println(htmlpage);
23794 govind 107
			currentSmsCount = Integer.parseInt(htmlpage);
108
			log.info("Got successfully parsed {}", currentSmsCount);
109
			propertiesDetails.put("currentSmsCount",Integer.toString(currentSmsCount));
110
			writeToPropertiesFile.saveParamChanges(propertiesDetails,nagiosPropertiesFile);
111
 
112
 
23723 amit.gupta 113
		}
23794 govind 114
 
23723 amit.gupta 115
	}
23794 govind 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
 
140
	}
23723 amit.gupta 141
}