Search in sources :

Example 1 with AccountLogger

use of com.zimbra.common.util.AccountLogger in project zm-mailbox by Zimbra.

the class SoapProvisioning method getAllAccountLoggers.

/**
 * Returns all account loggers for the given server.  The <tt>Map</tt>'s key is
 * the account name, and values are all the <tt>AccountLogger</tt> objects for
 * that account.
 *
 * @server the server name, or <tt>null</tt> for the local server
 */
public Map<String, List<AccountLogger>> getAllAccountLoggers(String server) throws ServiceException {
    if (server == null) {
        server = getLocalServer().getName();
    }
    GetAllAccountLoggersResponse resp = invokeJaxb(new GetAllAccountLoggersRequest(), server);
    Map<String, List<AccountLogger>> result = new HashMap<String, List<AccountLogger>>();
    for (AccountLoggerInfo acctLogger : resp.getLoggers()) {
        String acctName = acctLogger.getName();
        result.put(acctName, accountLoggersFromLoggerInfos(acctLogger.getLoggers(), acctName));
    }
    return result;
}
Also used : GetAllAccountLoggersRequest(com.zimbra.soap.admin.message.GetAllAccountLoggersRequest) HashMap(java.util.HashMap) AccountLogger(com.zimbra.common.util.AccountLogger) AccountLoggerInfo(com.zimbra.soap.admin.type.AccountLoggerInfo) GetAllAccountLoggersResponse(com.zimbra.soap.admin.message.GetAllAccountLoggersResponse) ArrayList(java.util.ArrayList) List(java.util.List) DistributionList(com.zimbra.cs.account.DistributionList)

Example 2 with AccountLogger

use of com.zimbra.common.util.AccountLogger in project zm-mailbox by Zimbra.

the class GetAllAccountLoggers method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Server localServer = Provisioning.getInstance().getLocalServer();
    checkRight(zsc, context, localServer, Admin.R_manageAccountLogger);
    Provisioning prov = Provisioning.getInstance();
    Map<String, Element> accountElements = new HashMap<String, Element>();
    Element response = zsc.createElement(AdminConstants.GET_ALL_ACCOUNT_LOGGERS_RESPONSE);
    for (AccountLogger al : LogFactory.getAllAccountLoggers()) {
        // Look up account
        Account account = prov.get(AccountBy.name, al.getAccountName(), zsc.getAuthToken());
        if (account == null) {
            ZimbraLog.misc.info("GetAllAccountLoggers: unable to find account '%s'.  Ignoring account logger.", al.getAccountName());
            continue;
        }
        // Add elements
        Element eAccountLogger = accountElements.get(account.getId());
        if (eAccountLogger == null) {
            eAccountLogger = response.addElement(AdminConstants.E_ACCOUNT_LOGGER);
            accountElements.put(account.getId(), eAccountLogger);
        }
        eAccountLogger.addAttribute(AdminConstants.A_ID, account.getId());
        eAccountLogger.addAttribute(AdminConstants.A_NAME, account.getName());
        Element eLogger = eAccountLogger.addElement(AdminConstants.E_LOGGER);
        eLogger.addAttribute(AdminConstants.A_CATEGORY, al.getCategory());
        eLogger.addAttribute(AdminConstants.A_LEVEL, al.getLevel().toString());
    }
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) Server(com.zimbra.cs.account.Server) HashMap(java.util.HashMap) AccountLogger(com.zimbra.common.util.AccountLogger) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning)

Example 3 with AccountLogger

use of com.zimbra.common.util.AccountLogger in project zm-mailbox by Zimbra.

the class TestLog method removeAll.

/**
 * Tests removing all account loggers for a given account.
 */
@Test
public void removeAll() throws Exception {
    SoapProvisioning prov = TestUtil.newSoapProvisioning();
    Account user1 = TestUtil.createAccount(USER_1);
    Account user2 = TestUtil.createAccount(USER_2);
    prov.addAccountLogger(user1, "zimbra.soap", "debug", null);
    prov.addAccountLogger(user1, "zimbra.sync", "debug", null);
    prov.addAccountLogger(user2, "zimbra.soap", "debug", null);
    prov.addAccountLogger(user2, "zimbra.sync", "debug", null);
    // Test removing loggers with no category specified.
    List<AccountLogger> loggers = prov.getAccountLoggers(user1, null);
    assertEquals(String.format("Number of loggers for acct=%s", USER_1), 2, loggers.size());
    prov.removeAccountLoggers(user1, null, null);
    loggers = prov.getAccountLoggers(user1, null);
    assertEquals(String.format("Number of loggers for acct=%s after remove with null category/null svr", USER_1), 0, loggers.size());
    // Test removing loggers with category "all".
    loggers = prov.getAccountLoggers(user2, null);
    assertEquals(String.format("Number of loggers for acct=%s", USER_2), 2, loggers.size());
    prov.removeAccountLoggers(user2, "all", null);
    loggers = prov.getAccountLoggers(user2, null);
    assertEquals(String.format("Number of loggers for acct=%s after remove with category='all'/null svr", USER_2), 0, loggers.size());
}
Also used : Account(com.zimbra.cs.account.Account) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) AccountLogger(com.zimbra.common.util.AccountLogger) Test(org.junit.Test)

Example 4 with AccountLogger

use of com.zimbra.common.util.AccountLogger in project zm-mailbox by Zimbra.

the class TestLog method accountLoggers.

@Test
public void accountLoggers() throws Exception {
    SoapProvisioning prov = TestUtil.newSoapProvisioning();
    Account user1 = TestUtil.createAccount(USER_1);
    Account user2 = TestUtil.createAccount(USER_2);
    Account user3 = TestUtil.createAccount(USER_3);
    Account user4 = TestUtil.createAccount(USER_4);
    // Add loggers.
    List<AccountLogger> loggers = prov.addAccountLogger(user1, "zimbra.filter", "debug", null);
    assertLoggerExists(loggers, user1, "zimbra.filter", Level.debug);
    loggers = prov.addAccountLogger(user2, "zimbra.backup", "info", null);
    assertLoggerExists(loggers, user2, "zimbra.backup", Level.info);
    loggers = prov.addAccountLogger(user3, "zimbra.sync", "warn", null);
    assertLoggerExists(loggers, user3, "zimbra.sync", Level.warn);
    loggers = prov.addAccountLogger(user3, "zimbra.lmtp", "warn", null);
    assertLoggerExists(loggers, user3, "zimbra.lmtp", Level.warn);
    assertEquals(String.format("Number of loggers for acct=%s", USER_3), 1, loggers.size());
    loggers = prov.addAccountLogger(user4, "zimbra.lmtp", "error", null);
    assertLoggerExists(loggers, user4, "zimbra.lmtp", Level.error);
    // Verify <GetAccountLoggersRequest>.
    loggers = prov.getAccountLoggers(user1, null);
    assertEquals(String.format("Number of loggers for acct=%s", USER_1), 1, loggers.size());
    assertLoggerExists(loggers, user1, "zimbra.filter", Level.debug);
    loggers = prov.getAccountLoggers(user2, null);
    assertEquals(String.format("Number of loggers for acct=%s", USER_2), 1, loggers.size());
    assertLoggerExists(loggers, user2, "zimbra.backup", Level.info);
    loggers = prov.getAccountLoggers(user3, null);
    assertEquals(String.format("Number of loggers for acct=%s", USER_3), 2, loggers.size());
    assertLoggerExists(loggers, user3, "zimbra.sync", Level.warn);
    assertLoggerExists(loggers, user3, "zimbra.lmtp", Level.warn);
    loggers = prov.getAccountLoggers(user4, null);
    assertEquals(String.format("Number of loggers for acct=%s", USER_4), 1, loggers.size());
    assertLoggerExists(loggers, user4, "zimbra.lmtp", Level.error);
    // Remove loggers for everyone except user3.
    prov.removeAccountLoggers(user1, "zimbra.filter", null);
    prov.removeAccountLoggers(user2, null, null);
    prov.removeAccountLoggers(user4, null, null);
    // Test <GetAllAccountLoggersRequest>.
    Map<String, List<AccountLogger>> map = prov.getAllAccountLoggers(null);
    assertEquals("Size of map from getAllAccountLoggers", 1, map.size());
    loggers = map.get(user3.getName());
    assertEquals(String.format("Number of loggers for acct=%s", USER_3), 2, loggers.size());
    assertLoggerExists(loggers, user3, "zimbra.sync", Level.warn);
    assertLoggerExists(loggers, user3, "zimbra.lmtp", Level.warn);
}
Also used : Account(com.zimbra.cs.account.Account) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) AccountLogger(com.zimbra.common.util.AccountLogger) List(java.util.List) Test(org.junit.Test)

Example 5 with AccountLogger

use of com.zimbra.common.util.AccountLogger in project zm-mailbox by Zimbra.

the class TestLog method allCategories.

/**
 * Confirms that account loggers are added for all categories when the
 * category name is set to "all" (bug 29715).
 */
@Test
public void allCategories() throws Exception {
    SoapProvisioning prov = TestUtil.newSoapProvisioning();
    Account account = TestUtil.createAccount(USER_1);
    assertEquals(String.format("Number of loggers for acct=%s after acct creation", USER_1), 0, prov.getAccountLoggers(account, null).size());
    List<AccountLogger> loggers = prov.addAccountLogger(account, "all", "debug", null);
    assertTrue(String.format("Number of loggers (%s) for acct=%s at debug level should be greater than 1", loggers.size(), USER_1), loggers.size() > 1);
    // Make sure the zimbra.soap category was affected.
    assertLoggerExists(loggers, account, "zimbra.soap", Level.debug);
    loggers = prov.getAccountLoggers(account, null);
    assertLoggerExists(loggers, account, "zimbra.soap", Level.debug);
}
Also used : Account(com.zimbra.cs.account.Account) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) AccountLogger(com.zimbra.common.util.AccountLogger) Test(org.junit.Test)

Aggregations

AccountLogger (com.zimbra.common.util.AccountLogger)11 Account (com.zimbra.cs.account.Account)8 SoapProvisioning (com.zimbra.cs.account.soap.SoapProvisioning)8 List (java.util.List)4 Test (org.junit.Test)3 Element (com.zimbra.common.soap.Element)2 Server (com.zimbra.cs.account.Server)2 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 DistributionList (com.zimbra.cs.account.DistributionList)1 Provisioning (com.zimbra.cs.account.Provisioning)1 GetAllAccountLoggersRequest (com.zimbra.soap.admin.message.GetAllAccountLoggersRequest)1 GetAllAccountLoggersResponse (com.zimbra.soap.admin.message.GetAllAccountLoggersResponse)1 AccountLoggerInfo (com.zimbra.soap.admin.type.AccountLoggerInfo)1