|
|
| Line 1: | |||
| + | This script shows you all the agents in the system a given user can access. This report has to be used in conjunction with a report template such as the [[Bar Chart Template]]. | ||
| + | ---- | ||
| + | ''Meta-Data Script:'' | ||
| + | <pre>// Meta Data | ||
| + | import com.urbancode.anthill3.domain.project.*; | ||
| + | import com.urbancode.anthill3.domain.reporting.*; | ||
| + | import com.urbancode.anthill3.domain.authentication.*; | ||
| + | ReportMetaData rmd = new ReportMetaData(); | ||
| + | TextParamMetaData userNameParam = new TextParamMetaData(); | ||
| + | userNameParam.setName("username"); | ||
| + | userNameParam.setLabel("Username"); | ||
| + | userNameParam.setDescription("The username to report on."); | ||
| + | userNameParam.setRequired(true); | ||
| + | rmd.addParameter(userNameParam); | ||
| + | AuthenticationRealm[] realms = AuthenticationRealmFactory.getInstance().restoreAllActive(); | ||
| + | String[] labels = new String[realms.length]; | ||
| + | String[] values = new String[realms.length]; | ||
| + | for (int i = 0; i < realms.length; i++) { | ||
| + | labels[i] = realms[i].getName(); | ||
| + | values[i] = realms[i].getName(); | ||
| + | } | ||
| + | SelectParamMetaData params = new SelectParamMetaData(); | ||
| + | params.setLabels(labels); | ||
| + | params.setValues(values); | ||
| + | params.setName("realmName"); | ||
| + | params.setLabel("Authentication Realm"); | ||
| + | params.setDescription("The User Authentication Realm"); | ||
| + | params.setRequired(true); | ||
| + | rmd.addParameter(params); | ||
| + | // Configure columns | ||
| + | rmd.addColumn("AgentName"); | ||
| + | return rmd; | ||
| + | </pre> | ||
| + | ---- | ||
| + | ''Context Script:'' | ||
| + | <pre>import com.urbancode.anthill3.domain.security.*; | ||
| + | import com.urbancode.anthill3.domain.servergroup.*; | ||
| + | import com.urbancode.anthill3.domain.reporting.*; | ||
| + | import com.urbancode.anthill3.domain.agent.*; | ||
| + | import com.urbancode.devilfish.client.*; | ||
| + | import java.util.*; | ||
| + | Set environments = new HashSet(); | ||
| + | Set agents = new HashSet(); | ||
| + | ServerGroup[] serverGroups = ServerGroupFactory.getInstance().restoreAll(); | ||
| + | for (int i = 0; i < serverGroups.length; i++) { | ||
| + | User[] users = Authority.getInstance().getUsersWithPermissionToPersistent(serverGroups[i], "read"); | ||
| + | for (int j = 0; j < users.length; j++) { | ||
| + | User user = users[j]; | ||
| + | if (user.getName().equals(username) && | ||
| + | user.getAuthenticationRealm().getName().equals(realmName)) { | ||
| + | environments.add(serverGroups[i]); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | Iterator itr = environments.iterator(); | ||
| + | while (itr.hasNext()) { | ||
| + | ServerGroup serverGroup = (ServerGroup) itr.next(); | ||
| + | agents.addAll(Arrays.asList(serverGroup.getServerArray())); | ||
| + | } | ||
| + | ReportOutput output = new ReportOutput(metaData); | ||
| + | itr = agents.iterator(); | ||
| + | while (itr.hasNext()) { | ||
| + | ServiceEndpoint serviceEndpoint = (ServiceEndpoint) itr.next(); | ||
| + | Agent agent = AgentFactory.getInstance().restoreByEndpoint(serviceEndpoint); | ||
| + | ReportRow row = new ReportRow(output, "Agent"); | ||
| + | row.setColumnValue("AgentName", agent.getName()); | ||
| + | output.addRow(row); | ||
| + | } | ||
| + | return output; | ||
| + | </pre> | ||
| + | ---- | ||
| + | '''Related Content''' | ||
| + | [[AnthillPro Template Reports]]<br/> | ||
| + | [[Report Templates]] | ||