Subversion Repositories SmartDukaan

Rev

Rev 5536 | Rev 5674 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5536 Rev 5563
Line 33... Line 33...
33
    public static void main(String[] args) {
33
    public static void main(String[] args) {
34
    	AlertTask alertTask = new AlertTask();
34
    	AlertTask alertTask = new AlertTask();
35
    	entitiesToBeAlerted = entityHandler.getEntitiesToBeAlerted();
35
    	entitiesToBeAlerted = entityHandler.getEntitiesToBeAlerted();
36
    	
36
    	
37
    	for(MonitoredEntity entity : entitiesToBeAlerted) {
37
    	for(MonitoredEntity entity : entitiesToBeAlerted) {
38
    		if(entity.getCriticalExpiryTime() >= (new Date()).getTime()) {
38
    		if(entity.getCriticalExpiryTime() <= (new Date()).getTime()) {
39
    			if(alert(entity, EntityProcessedState.CRITICAL_SENT)) {
39
    			if(alert(entity, EntityProcessedState.CRITICAL_SENT)) {
40
    				entityHandler.updateEntityProcessedState(entity.getId(), 
40
    				entityHandler.updateEntityProcessedState(entity.getId(), 
41
    						EntityProcessedState.CRITICAL_SENT);
41
    						EntityProcessedState.CRITICAL_SENT);
42
    			}
42
    			}
43
    		} else if(entity.getWarnExpiryTime() >= (new Date()).getTime()) {
43
    		} else if(entity.getWarnExpiryTime() <= (new Date()).getTime()) {
44
    			if(alert(entity, EntityProcessedState.WARNING_SENT)) {
44
    			if(alert(entity, EntityProcessedState.WARNING_SENT)) {
45
    				entityHandler.updateEntityProcessedState(entity.getId(), 
45
    				entityHandler.updateEntityProcessedState(entity.getId(), 
46
    						EntityProcessedState.WARNING_SENT);
46
    						EntityProcessedState.WARNING_SENT);
47
    			}
47
    			}
48
    		}
48
    		}
Line 61... Line 61...
61
				userIds = alertMap.getUserIds();
61
				userIds = alertMap.getUserIds();
62
				sendTo = userIds.split(";");
62
				sendTo = userIds.split(";");
63
			} else {
63
			} else {
64
				EntityMonitoringStatus entityMonitoringStatus = 
64
				EntityMonitoringStatus entityMonitoringStatus = 
65
					entityHandler.getEntityMonitoringStatus(entity.getEntityType());
65
					entityHandler.getEntityMonitoringStatus(entity.getEntityType());
-
 
66
				sendTo = entityMonitoringStatus.getUserIds().split(";");
66
				sendTo[0] = "amar.kumar@shop2020.in";
67
				//sendTo[0] = "amar.kumar@shop2020.in";
67
			}
68
			}
68
			System.out.println(sendTo);
69
			System.out.println(sendTo);
69
			if(userIds!=null && userIds!="") {
70
			//if(userIds!=null && userIds!="") {
70
				
71
				
71
				String emailFromAddress = "build@shop2020.in";
72
				String emailFromAddress = "build@shop2020.in";
72
		        String password = "cafe@nes";
73
		        String password = "cafe@nes";
73
		        String emailSubjectTxt = null;
74
		        String emailSubjectTxt = null;
74
		        String emailMsgTxt = null;
75
		        String emailMsgTxt = null;
Line 82... Line 83...
82
					emailSubjectTxt = "Critical Alert for " + entity.getEntityType() 
83
					emailSubjectTxt = "Critical Alert for " + entity.getEntityType() 
83
					+ " : " + entity.getEntityIdentifier() + " in "+delayedEventDescription;
84
					+ " : " + entity.getEntityIdentifier() + " in "+delayedEventDescription;
84
					emailMsgTxt = "Critical Time expired for "+ entity.getEntityType() 
85
					emailMsgTxt = "Critical Time expired for "+ entity.getEntityType() 
85
					+ " : " + entity.getEntityIdentifier() + " in "+delayedEventDescription;
86
					+ " : " + entity.getEntityIdentifier() + " in "+delayedEventDescription;
86
				}
87
				}
87
				GmailUtils utils = new GmailUtils();
88
				in.shop2020.alert.util.GmailUtils utils = new in.shop2020.alert.util.GmailUtils();
88
		        try {
89
		        try {
89
		        	System.out.println("Just before mail");
90
		        	System.out.println("Just before mail");
90
					utils.sendSSLMessage(sendTo, emailSubjectTxt, emailMsgTxt, emailFromAddress, password, "");
91
		        	utils.sendSSLMessage(sendTo, emailSubjectTxt, emailMsgTxt, emailFromAddress, password);
91
				} catch (MessagingException e) {
92
				} catch (MessagingException e) {
92
					log.error("Unable to send "+state+" Alert for " + entity.getEntityType() 
93
					log.error("Unable to send "+state+" Alert for " + entity.getEntityType() 
93
							+ " : " + entity.getEntityIdentifier() + e);
94
							+ " : " + entity.getEntityIdentifier() + e);
94
					return false;
95
					return false;
95
				}
96
				}
96
				return true;
97
				return true;
97
			}
98
			//}
98
		} catch(Exception e) {
99
		} catch(Exception e) {
99
			log.error("Unable to send Alert for " + entity.getEntityType() 
100
			log.error("Unable to send Alert for " + entity.getEntityType() 
100
								+ " : " + entity.getEntityIdentifier() + e.getMessage() + e.getStackTrace() +
101
								+ " : " + entity.getEntityIdentifier() + e.getMessage() + e.getStackTrace() +
101
								e.getCause() + e.getLocalizedMessage());
102
								e.getCause() + e.getLocalizedMessage());
102
		}
103
		}