Subversion Repositories SmartDukaan

Rev

Rev 24891 | 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.IOException;
23723 amit.gupta 4
import java.util.HashMap;
23794 govind 5
import java.util.LinkedHashMap;
23723 amit.gupta 6
import java.util.Map;
7
 
23755 amit.gupta 8
import org.apache.logging.log4j.LogManager;
9
import org.apache.logging.log4j.Logger;
23723 amit.gupta 10
import org.springframework.beans.factory.annotation.Autowired;
23794 govind 11
import org.springframework.beans.factory.annotation.Value;
23723 amit.gupta 12
import org.springframework.stereotype.Component;
13
 
23794 govind 14
import com.smartdukaan.cron.properties.WriteToPropertiesFile;
23723 amit.gupta 15
import com.spice.profitmandi.common.enumuration.SchemeType;
23794 govind 16
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
17
import com.spice.profitmandi.common.model.RechargeCredential;
23723 amit.gupta 18
import com.spice.profitmandi.common.web.client.RestClient;
23731 amit.gupta 19
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
23794 govind 20
import com.spice.profitmandi.service.recharge.RechargeService;
21
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
23723 amit.gupta 22
 
23
@Component
24
public class NagiosMonitorTasks {
25
 
23755 amit.gupta 26
	private static final Logger log = LogManager.getLogger(NagiosMonitorTasks.class);
23723 amit.gupta 27
 
23794 govind 28
	@Value("${think.walnut.digital.recharge.transaction.mobile.url}")
29
	private String thinkWalnutDigitalRechargeTransactionMobileUrl;
30
 
31
	@Value("${think.walnut.digital.recharge.transaction.dth.url}")
32
	private String thinkWalnutDigitalRechargeTransactionDthUrl;
33
 
34
	@Value("${think.walnut.digital.recharge.enquiry.url}")
35
	private String thinkWalnutDigitalRechargeEnquiryUrl;
36
 
37
	@Value("${think.walnut.digital.recharge.balance.url}")
38
	private String thinkWalnutDigitalRechargeBalanceUrl;
39
 
40
	@Value("${think.walnut.digital.recharge.username}")
41
	private String thinkWalnutDigitalRechargeUserName;
42
 
43
	@Value("${think.walnut.digital.recharge.password}")
44
	private String thinkWalnutDigitalRechargePassword;
45
 
46
	@Value("${think.walnut.digital.recharge.auth.key}")
47
	private String thinkWalnutDigitalRechargeAuthKey;
48
 
23723 amit.gupta 49
	@Autowired
23794 govind 50
	private ThinkWalnutDigitalRechargeProviderService thinkWalnutDigitalRechargeProviderService;
24121 govind 51
 
23794 govind 52
	@Autowired
23723 amit.gupta 53
	private RestClient restClient;
23794 govind 54
 
55
	@Autowired
56
	ItemRepository itemRepository;
24121 govind 57
 
23731 amit.gupta 58
	@Autowired
23794 govind 59
	private RechargeService rechargeService;
23723 amit.gupta 60
 
23794 govind 61
	@Autowired
62
	private WriteToPropertiesFile writeToPropertiesFile;
63
 
24121 govind 64
	String nagiosPropertiesFile = "/var/log/services/nagios-Monitoring.properties";
65
 
23723 amit.gupta 66
	public void reportSmsCount() throws Throwable {
67
		String htmlpage;
23794 govind 68
		int currentSmsCount = 0;
24121 govind 69
		LinkedHashMap<String, String> propertiesDetails = new LinkedHashMap<>();
24879 govind 70
		String uri = "/MessagingGateway/GetSMSBalance";
23723 amit.gupta 71
		Map<String, String> params = new HashMap<>();
24879 govind 72
		params.put("Username", "srlsaholic");
73
		params.put("Password", "sr18mar");
23723 amit.gupta 74
		String response = restClient.post(SchemeType.HTTP, "103.15.179.45", 8085, uri, params, new HashMap<>());
75
		// System.out.println("response Html"+response);
76
		if (response.length() > 0) {
24879 govind 77
			htmlpage = response.substring(response.indexOf("=")+1);
78
			 System.out.println(htmlpage);
24891 amit.gupta 79
			currentSmsCount = Integer.parseInt(htmlpage.trim());
23794 govind 80
			log.info("Got successfully parsed {}", currentSmsCount);
24121 govind 81
			propertiesDetails.put("currentSmsCount", Integer.toString(currentSmsCount));
82
			writeToPropertiesFile.saveParamChanges(propertiesDetails, nagiosPropertiesFile);
83
 
23723 amit.gupta 84
		}
24121 govind 85
 
23723 amit.gupta 86
	}
24121 govind 87
 
88
	public void currentThinkWalnutBalace() throws ProfitMandiBusinessException, IOException {
89
		LinkedHashMap<String, String> propertiesDetails = new LinkedHashMap<>();
23794 govind 90
		RechargeCredential thinkWalnutDigitalRechargeCredential = new RechargeCredential();
91
		thinkWalnutDigitalRechargeCredential.setRechargeUrl(thinkWalnutDigitalRechargeBalanceUrl);
92
		thinkWalnutDigitalRechargeCredential.setRechargeUserName(thinkWalnutDigitalRechargeUserName);
93
		thinkWalnutDigitalRechargeCredential.setRechargePassword(thinkWalnutDigitalRechargePassword);
94
		thinkWalnutDigitalRechargeCredential.setRechargeAuthKey(thinkWalnutDigitalRechargeAuthKey);
24121 govind 95
		float thinkWalnutBalance = thinkWalnutDigitalRechargeProviderService
96
				.doCheckBalanceRequest(thinkWalnutDigitalRechargeCredential);
97
		log.info("ThinkWalnut Balance {}", thinkWalnutBalance);
23794 govind 98
		propertiesDetails.put("thinkWalnutBalance", Float.toString(thinkWalnutBalance));
24121 govind 99
		writeToPropertiesFile.saveParamChanges(propertiesDetails, nagiosPropertiesFile);
100
 
23794 govind 101
	}
23723 amit.gupta 102
}