Subversion Repositories SmartDukaan

Rev

Rev 23723 | Rev 23730 | 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
 
3
import java.text.SimpleDateFormat;
4
import java.util.Date;
5
import java.util.HashMap;
6
import java.util.Map;
7
 
8
import org.slf4j.Logger;
9
import org.slf4j.LoggerFactory;
10
import org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.context.annotation.ComponentScan;
12
import org.springframework.scheduling.annotation.Scheduled;
13
import org.springframework.stereotype.Component;
14
 
15
import com.spice.profitmandi.common.enumuration.SchemeType;
16
import com.spice.profitmandi.common.web.client.RestClient;
17
 
18
@Component
19
@ComponentScan("com.smartdukaan.cron.*")
20
@ComponentScan("com.spice.profitmandi.common.*")
21
public class NagiosMonitorTasks {
22
 
23
	private static final Logger log = LoggerFactory.getLogger(NagiosMonitorTasks.class);
24
 
25
	private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
26
 
27
	@Autowired
28
	private RestClient restClient;
29
 
30
	@Scheduled(fixedRate = 5000)
31
	public void reportCurrentTime() {
32
		log.info("The time is now {}", dateFormat.format(new Date()));
33
	}
34
 
35
	@Scheduled(fixedRate = 5 * 60 * 1000)
36
	public void reportSmsCount() throws Throwable {
37
		String htmlpage;
38
		int currentBalance = 0;
39
		String uri = "/MessagingGateway/LoginAction";
40
		Map<String, String> params = new HashMap<>();
41
		params.put("user", "srlsaholic");
42
		params.put("password", "sr18mar");
43
		String response = restClient.post(SchemeType.HTTP, "103.15.179.45", 8085, uri, params, new HashMap<>());
44
		// System.out.println("response Html"+response);
45
		if (response.length() > 0) {
46
			htmlpage = response.substring(response.indexOf("Current Balance"), response.indexOf("</div>")).substring(
47
					(response.substring(response.indexOf("Current Balance"), response.indexOf("</div>")).indexOf(">"))
48
							+ 1,
49
					response.substring(response.indexOf("Current Balance"), response.indexOf("</div>")).length())
50
					.trim();
51
			/// System.out.println(htmlpage);
52
			currentBalance = Integer.parseInt(htmlpage);
53
			System.out.println(currentBalance);
54
		}
55
	}
56
}