Skip to content

Commit dd43f1d

Browse files
authored
Fixed fieldalias backup/restore
1 parent 6d4e858 commit dd43f1d

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

bin/splunkversioncontrol_backup_class.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,12 @@ def runQueries(self, app, endpoint, type, fieldIgnoreList, aliasAttributes={}, v
321321
elif type=="automatic lookup" and info["name"].find("LOOKUP-") == 0:
322322
logger.debug("i=\"%s\" Overriding name of name=\"%s\" of type=%s in app context app=%s with owner=%s to new name of newname=\"%s\"" % (self.stanzaName, info["name"], type, app, info["owner"], info["name"][7:]))
323323
info["name"] = info["name"][7:]
324-
324+
elif type=="fieldaliases":
325+
newName = info["name"]
326+
newName = newName[newName.find("FIELDALIAS-")+11:]
327+
logger.debug("Overriding name of %s of type %s in app context %s with owner %s to new name of %s" % (info["name"], type, app, info["owner"], newName))
328+
info["name"] = newName
329+
325330
#Some attributes are not used to create a new version so we remove them...(they may have been used above first so we kept them until now)
326331
for attribName in fieldIgnoreList:
327332
if info.has_key(attribName):
@@ -564,7 +569,7 @@ def calcfields(self, app):
564569

565570
def fieldaliases(self, app):
566571
ignoreList = [ "attribute", "type", "value" ]
567-
return self.runQueries(app, "/data/props/fieldaliases", "fieldaliases", ignoreList)
572+
return self.runQueries(app, "/data/props/fieldaliases", "fieldaliases", ignoreList, nameOverride="name")
568573

569574
def fieldextractions(self, app):
570575
ignoreList = [ "attribute" ]

bin/splunkversioncontrol_restore_class.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ def runRestore(self, config, type, endpoint, app, name, user, restoreAsUser, adm
326326

327327
#The config has an origName in it, therefore the object exists lookup may have not worked as expected
328328
#repeat it here for the edge cases (field extractions, field transforms and automatic lookups)
329+
origName = None
329330
if 'origName' in config:
330331
origName = config['origName']
331332
del config['origName']
@@ -362,7 +363,11 @@ def runRestore(self, config, type, endpoint, app, name, user, restoreAsUser, adm
362363

363364
#This is an existing object we are modifying
364365
if objExists == True:
365-
url = url + "/" + name
366+
createOrUpdate = "update"
367+
if origName:
368+
url = url + "/" + origName
369+
else:
370+
url = url + "/" + name
366371
del config["name"]
367372

368373
#Cannot post type/stanza when updating field extractions or a few other object types, but require them for creation?!

0 commit comments

Comments
 (0)