Management
Reply
Visitor
rooprob
Posts: 2
Registered: ‎02-26-2010
0

Finding Domain_ID from API

Hello,

in the perl API, function calls such as addPolicyObjects(), addServerObjects(), addAddressObjects() etc can all take an optional DOMAIN_ID parameter to add to specific subdomains in NSM.

 

The API test cases have used ID 1 to refer to the GLOBAL domain. I would like to use one of the many subdomains we've created. However I see no API call to obtain a list of valid domain IDs.  I can guess them from sequentially incrementing from 1 but this isn't going to be a workable solution outside of development.

 

In NSM you refer to these subdomains by name and there is no properies screen where I can see to resolve these to the ID.

 

Please help!

Recognized Expert Recognized Expert
Recognized Expert
CN
Posts: 316
Registered: ‎10-28-2008
0

Re: Finding Domain_ID from API

Let me check if there is a way to get the domain ID.

 

However, manually, you can look at the container domain that will have the ID of the specific domain. Using xdbViewEdit.sh script, select option 3 & select domain.

 

Thanks,
Chandra

 

New User
Mikael_Johnsson
Posts: 2
Registered: ‎02-01-2010
0

Re: Finding Domain_ID from API

[ Edited ]

Hello,

 

Did you ever manage to get an answer / find a solution to your question? I'm looking at the documentation and example-scripts for the API and there seems to be a few "gaps" in the documentation...

 

Regards

New User
nat_holloway
Posts: 1
Registered: ‎07-22-2010
0

Re: Finding Domain_ID from API

The domain ID starts with global=1 and each subdomain will be +1 after that one.  I had 2 other subdomains, however I had deleted 1 so mine came out as:

 

global = 1

Test = 2

Test2 = 4

 

I've foudn out that if you have domain admin permissions in global you can log into global and then specify DOMAIN_ID="2" to do work in that particular sub domain. 

 

Here's an example of a sub-routine to read all objects from the sub-domain DB (I borrowed example code):

 

sub readallhosts{
        my $t = shift;
        my ( $result, $values ) ;
  ( $result, $values )  = $client->getAllObjects(DOMAIN_ID=>"4");
  put_log('WARN', msg=>"Error while reading Host objects." ) unless( $result );
 
  while( my $hash = shift(@{$values} ) ){
    put_log('INFO', msg=>"Result ==> $hash->{'OBJECT_ID'} : $hash->{'OBJECT_NAME'}");
  }
}

K2
Regular Visitor
K2
Posts: 5
Registered: ‎09-13-2008
0

Re: Finding Domain_ID from API

Hi,

 

Thanks for your reply.

I get the idea of domain-numbers but what I was looking for was a way of getting all of the domains and their respective id's.

Like an SNMP-walk...

Since all (most) other commands require the domain-id, an API-call that would list all domains and id's seems like the most basic thing there should be in an API.

 

I guess I can write a loop that goes through ID's, but as you stated the numbers might not be in sequence, so there's no good way of knowing when the loop should stop.

 

Cheers

New User
mfreeman451
Posts: 6
Registered: ‎07-28-2011
0

Re: Finding Domain_ID from API

What is this xdbViewEdit.sh?

Visitor
strobert
Posts: 1
Registered: ‎09-14-2011
0

Re: Finding Domain_ID from API

Definitely have to agree with other posters that the NSM API docs have some "gaps" to be kind.

 

I cam here looking for the same answer.  I then think found it.  in the systems ervice (NSM has system,data,job and log service SOAP interfaceS) there is a GetSystemInfoRequest/GetSystemInfoResponse that should give the info.  in the MAIN/NSM.pm there is a getSystemInfo fucntion that invokes it.

 

looking at a raw dump of the output the data is in there.  next step processing it.

K2
Regular Visitor
K2
Posts: 5
Registered: ‎09-13-2008

Re: Finding Domain_ID from API

Hi,

 

You're spot on!

We managed to get past that stage a while back with a perl-script (see below).

You will need to add some info around this piece of code as it's only a part of our script...

 

###########################################################################
# Open SOAP-connection to NSM
###########################################################################
$SOAP::Constants::PATCH_HTTP_KEEPALIVE = 1;
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = '0';

my $connect = MAIN::NSM_AddPro->new('HOST'=>"$host", 'UNAME'=>"$user", 'PASSWD'=>"$passwd", 'PORT'=>"$port", 'DOMAIN'=> DOMAIN);
$connect->login;


###########################################################################
# Get all domain-names
###########################################################################
my ( $result, $xmlref )  = $connect->getSystemInfo('SERVICE_NAME'=>'domainName');                                                              

if( ( $result == TRUE ) && ( $xmlref->valueof( "//GetSystemInfoResponse/Status" ) =~ /Success/ ) ){
	#Log out:
	$connect->logout;

	if( defined( $xmlref->valueof( "//GetSystemInfoResponse/" ) ) ){
		my $data = $xmlref->valueof( "//GetSystemInfoResponse/" );

		#retrieve the values.
		print " Domains in NSM-server\n---------------------------------------------\n";

		my $counter=1;
		foreach my $domain (sort (@{$data->{'domainName'}})) {
			if ($counter++ % 3) {
				printf "%-35s","$domain";
			}
			else {
				printf "%-35s\n","$domain";
			}
		}
	}
}

Cheers

K2

Visitor
councilm
Posts: 2
Registered: ‎06-30-2008
0

Re: Finding Domain_ID from API

Just wanted to post my own experience and solution to this issue.  Working from K2's code, I have a short script that will print out the lists for 'domainId' and 'domainName'.  This code will output the results of the 'getSystemInfo' function and as you may be able to see, the result is a HASH reference that contains two ARRAY references.  The two arrays are ordered identically so the array indexes line up.

 

 

#!/usr/bin/perl
# Test script to get domainName/DOMAIN_ID's

use strict;
use warnings;
use MAIN::NSM;
use UTILS::COMMON;
use constant TRUE       => 1;
use constant FALSE      => 0;
## Setting some constants for user/pass/domain
use constant NSM_UNAME  => 'CHANGE_ME';             #NSM Username
use constant NSM_PASSWD => 'CHANGE_ME';        #NSM Password
use constant NSM_DOMAIN => 'global';            #NSM Domain

my ( $success,
     $host,
     $connect,
     $result,
     $xmlref
   );
my $t = shift;
put_log('TRACE', msg=>"\nLogging in.\n");

die("\nMissing HOSTNAME\n") unless $t;
$host = $t;

## Open connection to NSM
## uses constants from above.
$connect = MAIN::NSM->new(
        'HOST'=>"$host",
        'UNAME'=>NSM_UNAME,
        'PASSWD'=>NSM_PASSWD,
        'DOMAIN'=>NSM_DOMAIN,
);
$connect->login;

## Put test code here
## Some of this borrowed from "K2" of J-Net forums
print "Getting SystemInfo\n";
($result,$xmlref) = $connect->getSystemInfo('SERVICE_NAME'=>'domainName');

# Make the following IF statement shorter.
# Was the SOAP query successful? put answer into $success.
$success = ($xmlref->valueof("//GetSystemInfoResponse/Status") =~ /Success/);
if (($result == TRUE) && $success) {
  # if we had a successful SOAP call, make sure we have defined data.
  if (defined($xmlref->valueof("//GetSystemInfoResponse/" ))) {
    # Save that data ($data is a HASH referance)
    # $data = {
    #   'Status'    => 'scalar',
    #   'domainId   => 'array_ref',
    #   'domainName => 'array_ref',
    # };
    my $data = $xmlref->valueof("//GetSystemInfoResponse/" );

    print "\nBEGIN getSystemInfo data\n";
    # print out 'Status'
    print "Status: ",$data->{'Status'},"\n";
    # iterate through the two arrays
    # they are paired up based on index, so just count through them
    #  from 0 to size of one of the arrays (ie  scalar @array)
    for (my $i=0; $i < scalar @{$data->{'domainId'}}; $i++) {
      print "Array Index: $i\t ";
      print "DomainID: $data->{'domainId'}[$i]\t ";
      print "DomainName: $data->{'domainName'}[$i]\n";
    }
    print "\nEND getSystemInfo data\n";
  } ## if defined respose
} else{
  # oops, getSystemInfo failed.
  print "FAILED to get SystemInfo!\n\n";
} ## if success

## Close connection
put_log('TRACE', msg=>"\nLogging off.\n");
$connect->logout;
exit;


Copyright© 1999-2013 Juniper Networks, Inc. All rights reserved.