forked from SumoLogic/sumologic-python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmv-cat.py
More file actions
27 lines (23 loc) · 740 Bytes
/
mv-cat.py
File metadata and controls
27 lines (23 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Renames a category across all collectors and sources in a given account.
#
# python mv-cat.py <accessId> <accessKey> <fromName> <toName>
#
# TODO update query category constraints
# TODO regex
import sys
from sumologic import SumoLogic
args = sys.argv
sumo = SumoLogic(args[1], args[2])
fromCat, toCat = args[3], args[4]
cs = sumo.collectors()
for c in cs:
if 'category' in c and c['category'] == fromCat:
cv, etag = sumo.collector(c['id'])
cv['collector']['category'] = toCat
print(sumo.update_collector(cv, etag).text)
ss = sumo.sources(c['id'])
for s in ss:
if s['category'] == fromCat:
sv, etag = sumo.source(c['id'], s['id'])
sv['source']['category'] = toCat
print(sumo.update_source(c['id'], sv, etag).text)