| 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;
|
| 23738 |
amit.gupta |
14 |
import org.springframework.transaction.annotation.Transactional;
|
| 23723 |
amit.gupta |
15 |
|
|
|
16 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
|
|
17 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 23731 |
amit.gupta |
18 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 23723 |
amit.gupta |
19 |
|
|
|
20 |
@Component
|
| 23738 |
amit.gupta |
21 |
@Transactional(rollbackFor = Throwable.class)
|
| 23723 |
amit.gupta |
22 |
public class NagiosMonitorTasks {
|
|
|
23 |
|
|
|
24 |
private static final Logger log = LoggerFactory.getLogger(NagiosMonitorTasks.class);
|
|
|
25 |
|
|
|
26 |
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
|
|
|
27 |
|
|
|
28 |
@Autowired
|
|
|
29 |
private RestClient restClient;
|
| 23731 |
amit.gupta |
30 |
|
|
|
31 |
@Autowired
|
|
|
32 |
ItemRepository itemRepository;
|
| 23723 |
amit.gupta |
33 |
|
|
|
34 |
@Scheduled(fixedRate = 5000)
|
|
|
35 |
public void reportCurrentTime() {
|
|
|
36 |
log.info("The time is now {}", dateFormat.format(new Date()));
|
|
|
37 |
}
|
|
|
38 |
|
| 23731 |
amit.gupta |
39 |
@Scheduled(fixedRate = 30 * 60 * 1000)
|
| 23723 |
amit.gupta |
40 |
public void reportSmsCount() throws Throwable {
|
|
|
41 |
String htmlpage;
|
|
|
42 |
int currentBalance = 0;
|
|
|
43 |
String uri = "/MessagingGateway/LoginAction";
|
|
|
44 |
Map<String, String> params = new HashMap<>();
|
|
|
45 |
params.put("user", "srlsaholic");
|
|
|
46 |
params.put("password", "sr18mar");
|
|
|
47 |
String response = restClient.post(SchemeType.HTTP, "103.15.179.45", 8085, uri, params, new HashMap<>());
|
|
|
48 |
// System.out.println("response Html"+response);
|
|
|
49 |
if (response.length() > 0) {
|
|
|
50 |
htmlpage = response.substring(response.indexOf("Current Balance"), response.indexOf("</div>")).substring(
|
|
|
51 |
(response.substring(response.indexOf("Current Balance"), response.indexOf("</div>")).indexOf(">"))
|
|
|
52 |
+ 1,
|
|
|
53 |
response.substring(response.indexOf("Current Balance"), response.indexOf("</div>")).length())
|
|
|
54 |
.trim();
|
|
|
55 |
/// System.out.println(htmlpage);
|
|
|
56 |
currentBalance = Integer.parseInt(htmlpage);
|
| 23730 |
amit.gupta |
57 |
log.info("Got successfully parsed {}", currentBalance);
|
| 23723 |
amit.gupta |
58 |
}
|
|
|
59 |
}
|
| 23731 |
amit.gupta |
60 |
|
|
|
61 |
@Scheduled(fixedRate = 30 * 60 * 1000)
|
|
|
62 |
public void dbCheck() throws Throwable {
|
|
|
63 |
log.info("Connected to database successfully {}", itemRepository.isExistById(23));
|
|
|
64 |
}
|
| 23723 |
amit.gupta |
65 |
}
|