|
POST
|
I wanna know how to run a script automatically (via scheduled task or something else) that allows me to run the buffer to keep a service updated(a layer that shows the result in a web app with a map) . You do this by writing your .py script that performs the desired service updating, create a .bat or .cmd that starts python.exe and runs your .py script and then create the scheduled event to point to the .bat/.cmd file. The .bat should look something like this: C:\Python27\ArcGIS10.2\python.exe E:\MyScript.py
... View more
08-16-2016
05:54 AM
|
0
|
2
|
1744
|
|
POST
|
I can see the delay being a requirement. However, my scripting was for very basic reporting on service statuses (stopped or started) and that's it, I really have no need to actually stop/start them. Our organization is about 6 months into building out our AGS environment(s) with new waves of more data migrating out of old sde into new sde db's, more map/feature service publishing is planned. As we found in the first wave of this, not everything is published perfectly and requires making adjustments, so when you have other products being developed and built from these services that are prone to change (schema, attributes, layer indexes, etc.), those products tend to be susceptible to breakage. So... by incorporating a single-point GP service that has the single job of checking to see if a service is stopped or started, error and process handling can be built into the apps using those services.
... View more
08-15-2016
06:02 AM
|
0
|
0
|
1472
|
|
POST
|
We just have a simple need to check services to see STOPPED/STARTED status --- that's really it. Couple of reasons why: 1. To build a dashboard that can be displayed on a monitor hanging on the wall. Pretty simple .aspx page or something like that showing Red & Green for stopped/started services. 2. We have applications developed with the JavaScript API that other departments within the organization build and these utilize our ArcGIS Server services (map, feature & GP services). With the simple code below we published as a GP service that those applications can check against to see status and handle the appropriate methods if at runtime of their application it experiences a stopped service. Again, pretty simple yet has a lot of value. Part of the GP service that checks service status: def reviewRunning(token):
query_dict = { "f": "json", "token": token['token'] }
# query your services url
jsonResponse = urllib.urlopen(URL, urllib.urlencode(query_dict))
rooturl = agsurl + site + "/admin/services"
rootresp = json.loads(urllib.urlopen(rooturl + "?f=json", urllib.urlencode(query_dict)).read())
fldrs = rootresp['folders']
for fldr in fldrs:
fldrurl = agsurl + site + "/admin/services/" + fldr
query_dict = { "f": "json", "token": token['token'] }
svcresp = json.loads(urllib.urlopen(fldrurl + "?f=json", urllib.urlencode(query_dict)).read())
svcs = svcresp['services']
for svc in svcs:
svcname = svc['serviceName']
svctype = svc['type']
query_dict = { "f": "json", "token": token['token'] }
svcstatusurl = fldrurl + "/" + svcname + "." + svctype + "/status"
svcstatusresp = json.loads(urllib.urlopen(svcstatusurl + "?f=json", urllib.urlencode(query_dict)).read())
svcstatus = svcstatusresp['realTimeState']
print svcname, svctype, svcstatus
... View more
08-12-2016
05:59 AM
|
0
|
5
|
2968
|
|
DOC
|
I had issues implementing httpConn.getresponse() with our secured (https) ArcGIS Server sites. So, I simplified things and just load a JSON object and implement the "realTimeState" attribute for determining services that are stopped/started. Just pass in the token to the following def(): def reviewRunning(token): query_dict = { "f": "json", "token": token['token'] } # query your services url jsonResponse = urllib.urlopen(URL, urllib.urlencode(query_dict)) rooturl = agsurl + site + "/admin/services" rootresp = json.loads(urllib.urlopen(rooturl + "?f=json", urllib.urlencode(query_dict)).read()) fldrs = rootresp['folders'] for fldr in fldrs: fldrurl = agsurl + site + "/admin/services/" + fldr query_dict = { "f": "json", "token": token['token'] } svcresp = json.loads(urllib.urlopen(fldrurl + "?f=json", urllib.urlencode(query_dict)).read()) svcs = svcresp['services'] for svc in svcs: svcname = svc['serviceName'] svctype = svc['type'] query_dict = { "f": "json", "token": token['token'] } svcstatusurl = fldrurl + "/" + svcname + "." + svctype + "/status" svcstatusresp = json.loads(urllib.urlopen(svcstatusurl + "?f=json", urllib.urlencode(query_dict)).read()) svcstatus = svcstatusresp['realTimeState'] print svcname, svctype, svcstatus
... View more
08-11-2016
06:07 AM
|
0
|
0
|
3353
|
|
POST
|
I think you are correct. I did see reference to the notion that it's actually a pool of connections and you could issue a .close() to each/all. But also read that your .dispose() should be handling the disconnect. As a test I'd run a simple SELECT statement to see if you are getting the same strange result of only working on the first pass. If it works as expected, then perhaps the issue is at the db-level.
... View more
08-09-2016
08:24 AM
|
0
|
0
|
3122
|
|
POST
|
So the basic problem is: why does the tool work fine at the first run, but does nothing on the second run? Have you tried closing your connections to the sql db?
... View more
08-09-2016
07:15 AM
|
0
|
6
|
3122
|
|
POST
|
We are not running in ArcGIS Desktop, but we execute a python script from Windows Task Scheduler that updates a hosted Feature Service on our AGOL org account. I suppose you'd just need to grab the token by making calls against the REST API. It'd help to see what your script is doing. We used the majority of this https://blogs.esri.com/esri/arcgis/2014/01/24/updating-your-hosted-feature-service-for-10-2/ article to implement. Again, it's just authenticating directly with the ArcGIS.com REST API.
... View more
08-09-2016
07:09 AM
|
1
|
1
|
4438
|
|
POST
|
No problem, hijack away! Here's an idea to keeping credentials out of things. Well, sort of. You could just setup a simple .ini file to hold any credentials and then use base64 library in the python scritping. It's not a 100% secure approach, but it'd keep any hardcoded credentials out of the codebase and some low-level secuity using base64 to encode/decode that will essentially hide any variable values from view that might be set. Like so: *** create a "settings.ini" file and save it in the same directory as the .py script [AGS] USER = someusername PASS = somepassword The implement base64 and ConfigPaser in your .py scripting: import ConfigParser
import base64
# Find and gather settings from the settings.ini file
localPath = sys.path[0]
settingsFile = os.path.join(localPath, "settings.ini")
config = ConfigParser.ConfigParser()
config.read(settingsFile)
# Get encoded credentials
uname_encoded = base64.b64encode(config.get( 'AGS', 'USER'))
pwd_encoded = base64.b64encode(config.get('AGS', 'PASS'))
# use the encoded credentials for any login parameters
# for example, build the URL with credentials for the REST API
agsurl = 'https://yourAGSaddress'
site = '/arcgis'
URL = agsurl + site + "/rest/services"
# obtain a token
referer = agsurl
query_dict = { 'username': base64.b64decode(uname_encoded), 'password': base64.b64decode(pwd_encoded), 'referer': referer }
query_string = urllib.urlencode(query_dict)
url = agsurl + site + "/tokens/generateToken"
token = json.loads(urllib.urlopen(url + "?f=json", query_string).read())
#...blah blah blah you get the idea
... View more
08-04-2016
01:29 PM
|
2
|
4
|
2968
|
|
POST
|
We just downloaded 2.1 developer but have not had a chance to dig into it. Changing versions kicks off a bunch of work to rebuild, test and deploy several WAB's currently deployed to production --- hopefully by end of August we can start! Following this thread.
... View more
08-04-2016
07:13 AM
|
0
|
0
|
3136
|
|
POST
|
This looks like a really comprehensive tool set! But it's a bit much for what we need I think. To go from just running a simple script to check what services are stopped/running to this is pretty extreme. I'm not sure why the example script doesn't play nice with https. Seems like something do-able to overcome.
... View more
07-28-2016
11:39 AM
|
0
|
0
|
2968
|
|
POST
|
Thanks! Have you had a chance to setup the toolkit against HTTPS? I'd think we'd run into the same issues I'm hitting with the example REST API script.
... View more
07-28-2016
11:03 AM
|
0
|
7
|
3951
|
|
POST
|
I may revisit the REST API as there are some other complications to overcome with the approach I took. The issue with the REST API example is that it doesn't implement the requests library and instead uses urllib. Normally not an issue, however when dealing with https and TLS & SSL things start to just not work as originally written! This sends you down an entirely different path --- I may just try to re-write the sample using requests instead.
... View more
07-28-2016
09:31 AM
|
0
|
9
|
3951
|
|
POST
|
I ditched using the REST API calls (it's infuriating to navigate and determine all of the correct required server parameters). Simply opted for simplicity and accomplished this with urllib.open and properly setting up each individual url, taking care in constructing each one correctly. The REST API is overly complicated for my needs.
... View more
07-28-2016
07:53 AM
|
0
|
0
|
3951
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-17-2020 10:47 AM | |
| 1 | 10-25-2022 11:46 AM | |
| 1 | 08-08-2022 01:40 PM | |
| 1 | 02-15-2019 08:21 AM | |
| 2 | 08-14-2023 07:14 AM |
| Online Status |
Offline
|
| Date Last Visited |
01-22-2025
02:28 PM
|