Hi I am using GSuite Email Audit API to monitor the google users of Organization. But when I tried to create Monitor programattically using JAVA, it got failed to create monitors for some users.
I just wanted these Monitors should get created for users continue, hence I wrote cron of Google App Engine (GAE) for this.
Can anyone help me out.
My code sample is shown here:
import java.util.Calendar;
import com.google.gdata.client.appsforyourdomain.audit.AuditService;
import com.google.gdata.data.appsforyourdomain.generic.GenericEntry;
import com.google.gdata.client.appsforyourdomain.audit.MailMonitor;
...
MailMonitor monitor = new MailMonitor();
Calendar beginDate = Calendar.getInstance();
beginDate.set(beginDate.get(Calendar.YEAR),
beginDate.get(Calendar.MONTH), beginDate.get(Calendar.DATE),
beginDate.get(Calendar.HOUR_OF_DAY),beginDate.get(Calendar.MINUTE));
monitor.setBeginDate(beginDate.getTime());
Calendar endDate = Calendar.getInstance();
endDate.set(endDate.get(Calendar.YEAR), endDate.get(Calendar.MONTH),
endDate.get(Calendar.DATE) + 1, 23,59);
monitor.setEndDate(endDate.getTime());
monitor.setIncomingEmailMonitorLevel("FULL_MESSAGE");
monitor.setOutgoingEmailMonitorLevel("FULL_MESSAGE");
monitor.setDraftMonitorLevel("");
monitor.setChatMonitorLevel("");
monitor.setDestUserName("namrata");
try {
AuditService service = new AuditService( "example.com", "example.com-auditapp-v1");
service.setOAuth2Credentials(credential);
service.setContentType(ContentType.ATOM_ENTRY);
List<String> allUsers = getAllUsersList(domainName);
GenericEntry entry = null;
try {
for (int i = 0; i < allUsers.size(); i++) {
try {
entry =
service.createMailMonitor(allUsers.get(i),monitor);
} catch (Exception e) {
ErrorHandler.errorHandler(this.getClass().getSimpleName(),e);
}
}
} catch (Exception e) {
ErrorHandler.errorHandler(this.getClass().getSimpleName(),e);
}
} catch (AuthenticationException e) {
ErrorHandler.errorHandler(this.getClass().getSimpleName(),e);
} catch (Exception e) {
ErrorHandler.errorHandler(this.getClass().getSimpleName(),e);
}
The getAllUsersList() is a method where I get all users list that belongs to the domain. It shows programatticallly that monitors are get created on all users, but it just works for some of users, and for remaining users Monitors are not created. Thanks in advanced.