Subversion Repositories SmartDukaan

Rev

Rev 24891 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.smartdukaan.cron.monitored;

import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.smartdukaan.cron.properties.WriteToPropertiesFile;
import com.spice.profitmandi.common.enumuration.SchemeType;
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
import com.spice.profitmandi.common.model.RechargeCredential;
import com.spice.profitmandi.common.web.client.RestClient;
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
import com.spice.profitmandi.service.recharge.RechargeService;
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;

@Component
public class NagiosMonitorTasks {

        private static final Logger log = LogManager.getLogger(NagiosMonitorTasks.class);

        @Value("${think.walnut.digital.recharge.transaction.mobile.url}")
        private String thinkWalnutDigitalRechargeTransactionMobileUrl;

        @Value("${think.walnut.digital.recharge.transaction.dth.url}")
        private String thinkWalnutDigitalRechargeTransactionDthUrl;

        @Value("${think.walnut.digital.recharge.enquiry.url}")
        private String thinkWalnutDigitalRechargeEnquiryUrl;

        @Value("${think.walnut.digital.recharge.balance.url}")
        private String thinkWalnutDigitalRechargeBalanceUrl;

        @Value("${think.walnut.digital.recharge.username}")
        private String thinkWalnutDigitalRechargeUserName;

        @Value("${think.walnut.digital.recharge.password}")
        private String thinkWalnutDigitalRechargePassword;

        @Value("${think.walnut.digital.recharge.auth.key}")
        private String thinkWalnutDigitalRechargeAuthKey;

        @Autowired
        private ThinkWalnutDigitalRechargeProviderService thinkWalnutDigitalRechargeProviderService;

        @Autowired
        private RestClient restClient;

        @Autowired
        ItemRepository itemRepository;

        @Autowired
        private RechargeService rechargeService;

        @Autowired
        private WriteToPropertiesFile writeToPropertiesFile;

        String nagiosPropertiesFile = "/var/log/services/nagios-Monitoring.properties";

        public void reportSmsCount() throws Throwable {
                String htmlpage;
                int currentSmsCount = 0;
                LinkedHashMap<String, String> propertiesDetails = new LinkedHashMap<>();
                String uri = "/MessagingGateway/GetSMSBalance";
                Map<String, String> params = new HashMap<>();
                params.put("Username", "srlsaholic");
                params.put("Password", "sr18mar");
                String response = restClient.post(SchemeType.HTTP, "103.15.179.45", 8085, uri, params, new HashMap<>());
                // System.out.println("response Html"+response);
                if (response.length() > 0) {
                        htmlpage = response.substring(response.indexOf("=")+1);
                         System.out.println(htmlpage);
                        currentSmsCount = Integer.parseInt(htmlpage.trim());
                        log.info("Got successfully parsed {}", currentSmsCount);
                        propertiesDetails.put("currentSmsCount", Integer.toString(currentSmsCount));
                        writeToPropertiesFile.saveParamChanges(propertiesDetails, nagiosPropertiesFile);

                }

        }

        public void currentThinkWalnutBalace() throws ProfitMandiBusinessException, IOException {
                LinkedHashMap<String, String> propertiesDetails = new LinkedHashMap<>();
                RechargeCredential thinkWalnutDigitalRechargeCredential = new RechargeCredential();
                thinkWalnutDigitalRechargeCredential.setRechargeUrl(thinkWalnutDigitalRechargeBalanceUrl);
                thinkWalnutDigitalRechargeCredential.setRechargeUserName(thinkWalnutDigitalRechargeUserName);
                thinkWalnutDigitalRechargeCredential.setRechargePassword(thinkWalnutDigitalRechargePassword);
                thinkWalnutDigitalRechargeCredential.setRechargeAuthKey(thinkWalnutDigitalRechargeAuthKey);
                float thinkWalnutBalance = thinkWalnutDigitalRechargeProviderService
                                .doCheckBalanceRequest(thinkWalnutDigitalRechargeCredential);
                log.info("ThinkWalnut Balance {}", thinkWalnutBalance);
                propertiesDetails.put("thinkWalnutBalance", Float.toString(thinkWalnutBalance));
                writeToPropertiesFile.saveParamChanges(propertiesDetails, nagiosPropertiesFile);

        }
}