Select to view content in your preferred language

Query Services in ArcGIS Server Manager, then print the Original mxd document path and map service rest url

4429
15
Jump to solution
12-04-2018 01:12 PM
AndresCastillo
MVP Regular Contributor

I would like to find out the Original mxd document path (under the 'General' tab) and map service rest url (under the 'Capabilities' tab) from all services available in ArcGIS Server Manager, rather than using the UI webpage to drill down into each service to find out this info.

This would most likely involve using the ArcGIS Rest API for Server Administration.

So far, I have found the server manifest json file for a specific service using this documentation:

http://gis.esri.com/arcgis/admin/www/doc/index.html#/Service_Manifest/02w000000058000000/

This only lists the mxd path, but not the ms rest url.

In addition, this still only lists that information for one service only.

Ideally, a scripting language would be used to read the information for every service, and print it out to a document, such as a text file.

Any ideas?

0 Kudos
15 Replies
JakeSkinner
Esri Esteemed Contributor

This would take some trouble shooting.  I would recommend using an IDE such as PyScripter.  You can execute the script, and then enter in the variable 'dataSource' in the Python Interpreter.  This will provide further information.  Ex:

0 Kudos
AndresCastillo
MVP Regular Contributor

With respect to the keyerror, I believe that the script is aborting when it reaches a service that has no original document.

In ArcGIS Server Manager, that service has 'Service does not include path information.

Can you help me bypass this service so that the script continues?

What is the reasoning for lines 20-26?

I do not see any result from that codeblock.

In addition to your awesome code:

I would like to see in the result the urls for the different types of services.

For example:

https://domain:port/arcgis/rest/services/folder/serviceName/ImageServer

https://domain:port/arcgis/rest/services/folder/serviceName/MapServer

https://domain:port/arcgis/rest/services/folder/serviceName/FeatureServer

I also noted that if a service is stopped, the script will not read that service, so no output.

Yet, I would still like to know that information from the stopped services.

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Lines 20-26 read the ROOT directory (not a folder) of ArcGIS Server.  The script is working on stopped services and services that do not have an MXD:

ROOT
     Airports
          Untitled
     Monmouth_Parcels_AGS
          C:\TEMP\Python\UserData\Parcels.mxd
     Philadelphia2016
          C:\DATA\RASTER\Philadelphia\MosaicDataset.gdb\Philadelphia2016
Hosted
     Caltrans_Watersheds
          Untitled
     Monmouth_Parcels_HOSTED
          Untitled

To get the URL, you can add a print statement:

print(baseUrl + "/" + service['serviceName'] + '.' + service['type'])
AndresCastillo
MVP Regular Contributor

I see now that it is reading the stopped service, sorry

I also agree that it reads services with no original mxd as 'Untitled', so long as it has a machine name.

Yet, in this case, there is no machine name, nor path, for this service.

Machine name: Service does not include machine name information.

Path: Service does not include path information.

Can you help me bypass this service so that the script continues?

I tried stopping the service, doesn't work.

My organization is not yet confident regarding deleting this service without breaking something.

EDIT:

I was able to bypass this service by using a try, except keyerror, continue inside of the 'for service in services:" loop

More important for me though is:

In the ArcGIS Server Administrator Directory, I noticed that Feature Services are not displayed, whereas

in the ArcGIS REST Services Directory, they are.

As a result, the feature service URLs are not being printed out when they exist.

How do I get feature service urls to print as well?

0 Kudos
AndresCastillo
MVP Regular Contributor

Jake Skinner Employee ,

I've modified your script, starting at line 17 of your script in the 'correct answer.'

This is because the feature service (FS) url's do not seem to show up in the admin rest directory, but I would still like to include them.

See below.

These are the issues I am encountering as of now:

1

Only when I added the fs portion, the original path for services does not print to the result when its' not an mxd file type (for example, locators (E:\Locators\SiteAddressPoint) or toolboxes (C:\Users\name\AppData\Local\Esri\Desktop10.4\Staging\arcgis on serverDomain(publisher)\sddraftToolboxes\GeocodeAddresses_WorldLocator.tbx))

Without the fs portion on lines 30-39 below, this is no longer an issue.

2

When the script encounters the keyError, it continues, but prints to the result fs portion first for all fservices, then prints the keyError messages, then continues the remainder of the try statement to print the remainder mapservices and document paths.

I would like to keep the ms and fs urls printed out together.

baseUrl = "http://{}:6080/arcgis/admin/services".format(server)
baseUrl1 = "http://{}:6080/arcgis/rest/services".format(server)

catalog = json.load(urllib2.urlopen(baseUrl + "/" + "?token=" + token + "&f=json"))
catalog1 = json.load(urllib2.urlopen(baseUrl1 + "/" + "?token=" + token + "&f=json"))

print("ROOT")
services = catalog['services']
for service in services:
    if service['type']!= 'SteamServer':
        print("\t" + str(service['serviceName']))
        manifestUrl = baseUrl + "/" + service['serviceName'] + '.' + service['type'] + "/iteminfo/manifest/manifest.json" + "?token=" + token + "&f=json"
        dataSource = json.load(urllib2.urlopen(manifestUrl))
        print("\t\t" + dataSource['resources'][0]['onPremisePath'])
        

folders = catalog['folders']
for folderName in folders:
        if str(folderName) not in ('System', 'Utilities', 'DataStoreCatalogs'):
            print(str(folderName))
            print("________________________________________________________________________________")
            catalog = json.load(urllib2.urlopen(baseUrl + "/" + folderName + "/" + "?token=" + token + "&f=json"))
            services = catalog['services']
            for service in services:
                try:
                    print("\t" + str(service['serviceName']))
                    manifestUrl = baseUrl + "/" + str(folderName) + '/' + service['serviceName'] + '.' + service['type'] + "/iteminfo/manifest/manifest.json" + "?token=" + token + "&f=json"
                    dataSource = json.load(urllib2.urlopen(manifestUrl))
                    print("\t\t" + baseUrl + "/" + service['serviceName'] + '/' + service['type'])
                    folders1 = catalog1['folders']
                    for folderName in folders1:
                            if str(folderName) not in ('System', 'Utilities', 'DataStorecatalogs'):
                                catalog1 = json.load(urllib2.urlopen(baseUrl1 + "/" + folderName + "/" + "?token=" + token + "&f=json"))
                                services1 = catalog1['services']
                                for service in services1:
                                    if service['type'] == "FeatureServer":
                                        print("\t" + str(service['name']))
                                        print("\t\t" + baseUrl1 + "/" + service['name'] + '/' + service['type'])
                                        print("\n\n")
                    print("\t\t" + dataSource['resources'][0]['onPremisePath'])
                    print("\n\n")
                except KeyError:
                    print("KeyError: No original Document information")
                    print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
                    print("\n\n")
                    continue








#why is there no original path for services when its' not an mxd being printed out when added the fs portion?
#without the fs portion, the original path does print out
#when script encounters the keyError, it continues, but prints the fs portion first for all fservices, then prints the keyError messages, then continues the remainder of the try statement.
                
print("Script Complete")
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
AndresCastillo
MVP Regular Contributor

I also see this resource:

Example: Write properties of all services to a CSV file

https://enterprise.arcgis.com/en/server/10.4/administer/windows/example-write-properties-of-all-serv...

0 Kudos