Hi,
I have created a custom rest api to add a SQL instance to Foglight. I am doing a post call and within the api code are the internal function function calls that work on the installer. I am hitting a few hurdles on the way and seek some help if possible
1) The API code is able to register and create the agents both the DB_SQL_SERVER and the associated spi but then errors out with message - "VERBOSE [http-exec-51] script.system:dbwc_mssql_installer.monitorInstances - com.quest.qsi.fason.framework.installer.exceptions.InstallerServiceException: Could not create agent DB_SQL_Server on FglAM xxx: Not authorized to manage agents". Soon after it unregisters those agents.
2) If I try to enable OS monitoring, my API code fails with error - no credentials found for host xxxx. I think I am unable to populate credentialIDs for DBSS_Installer_OS_Credential topology object correctly in the code.
<type name='DBSS_Installer_OS_Credential' extends='DataObject'>
<annotation name='Keywords' value='DB_SQL_Server'/>
<property name='credentialIDs' type='String' is-many='true' is-containment='false'/>
<property name='lockboxPassword' type='String' is-many='false' is-containment='false'/>
<property name='osUserName' type='String' is-many='false' is-containment='false'/>
<property name='osPassword' type='String' is-many='false' is-containment='false'/>
<property name='authenticationMode' type='DBSS_Installer_DB_Authentication_Mode' is-many='false' is-containment='false'/>
</type>
Thanks
Hi,
On further investigation the error seems to emanate from: AsyncOperationStatusSL<Integer> operationStatus = this.ramService.initializeAgentAsync(remoteClient.getId(), agentType, agentName) - in com.quest.qsi.fason.framework.installer.impl.InstallerAgentServiceImpl class
Does the RemoteAgentManagementService i.e. " private RemoteAgentManagementService ramService = ServiceLocatorFactory.getLocator().getRemoteAgentManagementService();" defined in InstallerAgentServiceImpl has some restrictions in place e.g. it can't be called via api and so on?
2021-02-22 14:12:28.343 VERBOSE [http-exec-6] STDOUT - INFO - Creating xxx agent of type DB_SQL_Server on FglAM twi201023124519.estestau.wbctestau.westpac.com.au.
2021-02-22 14:12:28.343 INFO [http-exec-6] com.quest.qsi.fason.framework.installer.impl.InstallerAgentServiceImpl - Creating xxx agent of type DB_SQL_Server on FglAM yyy.
2021-02-22 14:12:28.343 VERBOSE [http-exec-6] script.system:dbwc_mssql_installer.monitorInstances - com.quest.qsi.fason.framework.installer.exceptions.InstallerServiceException: Could not create agent DB_SQL_Server on FglAM yyy: Not authorized to manage agents
Not sure how you called the related API. The message "Not authorized to manage agents" shows that the current user didn't have sufficient privileges to perform related action while foglight Administrator is required when managing agents through the API.
Regards
Jemy
Hi Jemy,
I am using my credentials to execute the API which has both Administrator and API roles. Any other ideas?
The installer works fine when a SQL instance is added via GUI or fglcmd.
Thanks
Per the given message, I would suggest to confirm again whether you generated the token from a user which has administrator and api roles. If yes, then try use Core API to create agent first, here InstallerAgentServiceImpl is not from Core but DB cartridge. Or you can consider using Core API to create an IC cartridge. If it's OK to do so, then it may be something to do with the API from DB cartridge. Or you can share your script if you confirm that the privileges are OK.
Regards
Jemy
Hi Jemy,
The rights in the token seem to be okay
I still have no idea whether you generated the token on an account which has admin and api roles.With sufficient privileges, using the run script rest api should be able to create agent, please refer to the help doc of rest api about how to generate token to execute the run script api.
I had a quick look at your code, it relies on DB cartridge too much. You may need to consult corresponding team(or support team) for further assistance. Here's an example about using Core API to create some IC agents. The code is to create some agents for the given fglam, just for your reference.
rms=server.RemoteAgentManagementService;
agentService=server.AgentService;
configService=server.ConfigService;
prefix="ICAgent_test_move"; //Agent name pattern
agentType="WindowsAgent"
eachHostAgentCount = 20;
monitoringHosts=["localhost","localhost"]
fglamName = 'myFglAM-1'
def count = 1;
def index = 0;
(1..10).each {
try {
log.info("counr $count, index $index");
agentName = prefix + it;
while(!createAgent(agentName, index)){
Thread.sleep(6000);
}
count++;
if (count >= eachHostAgentCount) {
if(index < monitoringHosts.size()){
index++;
}
count = 0;
}
}catch (Exception e){
log.info(e.message)
}
}
def createAgent(agentName, index) {
def fglam1 = findFglam(fglamName)
try {
if (fglam1 && !agentService.findByName(agentName)) {
log.info('Create agent!')
rms.initializeAgent(fglam1.id, agentType, agentName);
log.info('Agent instances!')
def agent = agentService.findByName(agentName)[0];
log.info("Agent $agent!")
def config = configService.getAgentInstancePrimaryAsp(agent.getAgentNamespace(), agent.getTypeId(), agent.getId());
config.setValueByString('host', monitoringHosts[index]);
config.setValueByString('hostNameOverride', agentName);
config.setValueByString('collectSystemId', "false");
configService.saveConfig(config);
}
}catch (Exception e) {
log.info(e.message)
return false;
}
if(fglam1){
return true;
}else{
return false;
}
}
return 'Done!'
def findFglam(name){
try{
return rms.findAllRemoteClients().find {
it.id.startsWith(name)
}
}catch(Exception e){
return null;
}
}
Regards
Jemy
Thanks Jemy
The generated token has both API and Admin access as can be identified by the role tag I posted above when I executed /security/login call (as below)
Thanks for the confirmation on the token. The API below are from Core while InstallerAgentServiceImpl is not from Core.
rms=server.RemoteAgentManagementService;
agentService=server.AgentService;
configService=server.ConfigService;
Hi Jemy,
I modified the code in the installer script to create the agent via CORE API. Still geeting the security exception. I have also updated my comments on the associated SR case.
srvRAM = server["RemoteAgentManagementService"];
srvRAM.initializeAgent(fglam1.id, DBSS_AGENT_TYPE, dbAgentName);
instead of “InstallerServiceFactory.getInstance().getAdAgentService().createAgent”, I still get the security exception “Not authorized to manage agents”
[http-exec-1] script.system:dbwc_mssql_installer.16
Starting to monitor instance dwd210122163030.ESDEVAU.WBCDEVAU.WESTPAC.COM.AU\A005E02.
Wed, 2021-02-24 16:43:47.761
[http-exec-1] script.system:dbwc_mssql_installer.16
Creating DB agent DWD210122163030.ESDEVAU.WBCDEVAU.WESTPAC.COM.AU-A005E02
Wed, 2021-02-24 16:43:47.761
[http-exec-1] script.system:dbwc_mssql_installer.16
java.lang.SecurityException: Not authorized to manage agents
Wed, 2021-02-24 16:43:47.761
[http-exec-1] script.system:dbwc_mssql_installer.16
Agent DWD210122163030.ESDEVAU.WBCDEVAU.WESTPAC.COM.AU-A005E02 already exists, check for a duplicate data.
Thanks
Here's a simple test about creating agent, including WindowsAgent and DB_SQL_Server Agent with related Core API. Other features like releasing lockbox, activate agent are not included and only some ASP configured in the test.
1. The code set to the Body of the rest api request in Postman
<ScriptBean> <script> <![CDATA[ rms=server.RemoteAgentManagementService; agentService=server.AgentService; configService=server.ConfigService; //set agent type and fglam ... agentType="DB_SQL_Server" //WindowsAgent if creating WindowsAgent monitoringHost="localhost" fglamName = 'qg95f7z2.prod.quest.corp' createAgent("testAgent3")//set the agent name you want to create def createAgent(agentName) { def fglam1 = findFglam(fglamName) try { if (fglam1 && !agentService.findByName(agentName)) { rms.initializeAgent(fglam1.id, agentType, agentName); def agent = agentService.findByName(agentName)[0]; def config = configService.getAgentInstancePrimaryAsp(agent.getAgentNamespace(), agent.getTypeId(), agent.getId()); /*test for DB_SQL_Server*/ config.setValueByString('monHost', monitoringHost); config.setValueByString('monICHostName', monitoringHost); config.setValueByString('monInstance', "test-instance"); /*test for IC*/ /* config.setValueByString('host', monitoringHost); config.setValueByString('hostNameOverride', agentName); config.setValueByString('collectSystemId', "false"); */ configService.saveConfig(config); } }catch (Exception e) { return false; } if(fglam1){ return true; }else{ return false; } } return 'Done!' def findFglam(name){ try{ return rms.findAllRemoteClients().find { it.id.startsWith(name) } }catch(Exception e){ return null; } } ]]> </script> </ScriptBean>
2. A screenshot of the test. I tried WindowsAgent and DB_SQL_Server and both were successfully.
3. I tried with foglight account, and sufficient roles were already granted to the foglight account.
4. The DB_SQL_Server agent I created.
5. I didn't face the exception "Not authorized to manage agents" from "script.system:dbwc_mssql_installer.16" as I only invoked Core API.
Through this way should be able to create the agent, and you can customize the code to include more features like setting more ASP, activating the agents, creating more agents at a time, etc...
Regards
Jemy