RESTAPI: Backup bigfix content to GIT repo - Windows
Log In or Register to download the BES file, and more.

0 Votes

Versioning - This is the latest version.

1TODO: Backup bigfix content to GIT repo - Windows1/10/2016 12:51:28 PM
2TODO: Backup bigfix content to GIT repo - Windows1/10/2016 7:25:47 PM
3RESTAPI: Backup bigfix content to GIT repo - Windows8/18/2016 10:49:06 AM

Description

 

This task requires a properly configured `besapi.conf` file to function. Details here: https://gist.github.com/jgstew/1b2da12af59b71c9f88a

This task does not install anything on the system it is running on and instead uses an embeded copy of Python as well as the lxml & requests libraries.

This is based upon BigFix Export code develeoped by Matt Hansen @ Penn State University that was modified by James Stewart @ UC Berkeley. (jgstew)

The source code for the BigFix export is here: https://gist.github.com/jgstew/1b2da12af59b71c9f88a

The BigFix Export code relies on a BESAPI python library also developed by Matt Hansen, and available here: https://github.com/CLCMacTeam/besapi

 

ToDos:

- Currently, the export folder must be "__Download\bigfix-content\", but in the future it should be configurable.

- Currently, the `besapi.conf` file must be plaintext and already on the machine. Ideally it would be encrypted or handled more securely.

- Handle long paths better (see known issues)

 

Known Issues:

- if the file for the BigFix content being exported will have a pathname that is too long (255+ chars) then this will fail entirely. The name of the exported item in bigfix is truncated to 70 chars by default to help prevent this, but this can be changed using the config file. In my testing, truncating it to 50 to 70 characters usually works, but this depends upon the name of the sites and the ID number of the item, so it can't be determined exactly without experimentation. Ideally the required amount of truncation would be determind on the fly for each item.

 


Property Details

ID21282
StatusAlpha - Code that was just developed
TitleRESTAPI: Backup bigfix content to GIT repo - Windows
DomainBESC
SourceInternal
Source IDjgstew
Source Release Date12/16/2015 12:00:00 AM
Is TaskTrue
Added by on 8/18/2016 10:49:06 AM
Last Modified by on 8/18/2016 10:49:06 AM
Counters 3566 Views / 70 Downloads
User Rating 1 star 2 star 3 star 4 star 5 star * Average over 0 ratings. ** Log In or Register to add your rating.

Relevance

isWindows (Relevance 1172)
Used in 1142 fixlets and 537 analyses   * Results in a true/false
Show indented relevance
windows of operating system
Used in 3 fixlets   * Results in a true/false
Show indented relevance
exists keys "repo" of sections "git" of files "besapi.conf" of (folders "temp" of windows folders; (it; folders "temp" of it; folders "tmp" of it; folders "etc" of it) of root folders of drives of system folders)

Actions

Action 1 (default)

Action Link Click here to deploy this action.
Script Type BigFix Action Script
// arbitrary user info used for the git commit message, but not related to the credentials used for auth
parameter "UserNameGIT" = "jgstew"
parameter "UserEmailGIT" = "jgstew@bigfix.me"
// CANNOT CONTAIN SPACES, MUST END IN \ :
parameter "ExportFolder" = "__Download\bigfix-content\"
// default log location is ephemeral
parameter "LogFile" = "__Download\git.log"

// ProductName: 7-Zip SFX
prefetch PortableGit.7z.exe sha1:eae5fab33d660e056167ef073b6dc287fc13cb31 size:30663256 https://github.com/git-for-windows/git/releases/download/v2.9.2.windows.1/PortableGit-2.9.2-32-bit.7z.exe sha256:d023e37c5e54d46900af4879e786ad107611ec9373fa348450fe844ab125a0a1
// prefetch PortableGit.7z.exe sha1:75dfd9284faf0e940baa3cdebec7148c88b91cc9 size:30531872 https://github.com/git-for-windows/git/releases/download/v2.9.2.windows.1/PortableGit-2.9.2-64-bit.7z.exe sha256:4319caf04f6e9b7bc4916660ce918e1d26cfc1c6ae5d19981d7ccab166117aca


// BESArchiver is the code that will actually export the BigFix content and push it to GIT

prefetch BESArchiver.zip sha1:cc35b645ace8672b7bd17ffb88444246d07c20e9 size:6046657 https://dl.dropboxusercontent.com/u/640753/BESArchiver-230e50a.zip sha256:9b07e083a25bbb6b14f2a21badc8a76e68771aabbbb9f1e0466b7c338940195d

// prefetch BESArchiver.zip sha1:990a98c4b7a71e385921a5399762a3b3c2aa2cce size:6035825 https://dl.dropboxusercontent.com/u/640753/BESArchiver-aa2bb87.zip sha256:b793fe75aa2fba9cfc8e1484b3f594a99dd6d286899e264a9d8c97a07b394eec

// - This unzip is a compiled verion of unzip v5.52 fom http://info-zip.org/
// - https://www.virustotal.com/en/file/8d9b5190aace52a1db1ac73a65ee9999c329157c8e88f61a772433323d6b7a4a/analysis
prefetch unzip.exe sha1:e1652b058195db3f5f754b7ab430652ae04a50b8 size:167936 http://software.bigfix.com/download/redist/unzip-5.52.exe sha256:8d9b5190aace52a1db1ac73a65ee9999c329157c8e88f61a772433323d6b7a4a

// ADD TO UTILITY CACHE:
utility __Download\unzip.exe
utility __Download\PortableGit.7z.exe

waithidden __Download\PortableGit.7z.exe -y -gm2 -o"__Download"

// EXTRACT using unzip:
waithidden __Download\unzip.exe -o "{pathname of file "BESArchiver.zip" of folder "__Download" of client folder of current site}" -d "{pathname of folder "__Download" of client folder of current site}"

// this seems to be required due to an issue with the newest PortableGIT
// http://stackoverflow.com/questions/3431361/git-for-windows-the-program-cant-start-because-libiconv2-dll-is-missing
// http://ss64.com/nt/robocopy.html
waithidden robocopy __Download\PortableGit\mingw32\bin __Download\PortableGit\mingw32\libexec\git-core *

// http://www-01.ibm.com/support/knowledgecenter/SS63NW_9.2.0/com.ibm.tivoli.tem.doc_9.2/Platform/Action/c_override.html
// http://www-01.ibm.com/support/knowledgecenter/SS63NW_9.2.0/com.ibm.tivoli.tem.doc_9.2/Platform/Action/c_action_log.html
action log command

wait __Download\PortableGit\cmd\git clone --no-checkout { preceding text of first "@" of unique value of keys "repo" of sections "git" of files "besapi.conf" of (folders "temp" of windows folders; (it; folders "temp" of it; folders "tmp" of it; folders "etc" of it) of root folders of drives of system folders) }:{ unique value of keys "password" of sections "git" of files "besapi.conf" of (folders "temp" of windows folders; (it; folders "temp" of it; folders "tmp" of it; folders "etc" of it) of root folders of drives of system folders) }@{ following text of first "@" of unique value of keys "repo" of sections "git" of files "besapi.conf" of (folders "temp" of windows folders; (it; folders "temp" of it; folders "tmp" of it; folders "etc" of it) of root folders of drives of system folders) } {parameter "ExportFolder"}

action log all

// http://superuser.com/questions/392061/how-to-make-a-shortcut-from-cmd
delete __createfile
createfile until END_OF_FILE
Set oWS = WScript.CreateObject("WScript.Shell")
sLinkFile = "{parameter "ExportFolder"}git.lnk"
Set oLink = oWS.CreateShortcut(sLinkFile)
oLink.TargetPath = "{pathname of download folder}\PortableGit\bin\git.exe"
oLink.WorkingDirectory = "{parameter "ExportFolder"}"
oLink.Save
END_OF_FILE
copy __createfile __Download\create_shortcut.vbs
waithidden cscript __Download\create_shortcut.vbs

if { not exists files ".gitignore" of folders "bigfix-content" of download folders }
// https://git-scm.com/docs/gitignore
delete __createfile
createfile until END_OF_FILE
git.exe.lnk
git.lnk
END_OF_FILE
copy __createfile {parameter "ExportFolder"}.gitignore
endif

// TODO: get timing info before and after this command to see how long it takes:
parameter "ExportBefore" = "{now}"
dos echo --- Export start: {parameter "ExportBefore"} >> {parameter "LogFile"} 2>&1
waithidden __Download\BESArchiver.exe >> {parameter "LogFile"} 2>&1
parameter "ExportAfter" = "{now}"
parameter "ExportTime" = "{ (parameter "ExportAfter") as time - (parameter "ExportBefore") as time }"
parameter "ExportExitCode" = "{exit codes of active actions}"
dos echo --- Export end: {parameter "ExportAfter"} >> {parameter "LogFile"} 2>&1
dos echo --- Export time: {parameter "ExportTime"} >> {parameter "LogFile"} 2>&1
dos echo --- Export exit code: {parameter "ExportExitCode"} >> {parameter "LogFile"} 2>&1

continue if{ exists (it as integer) whose(0=it) of (parameter "ExportExitCode") }

//dos echo [user]>> __Download\bigfix-content\.git\config
//dos echo name = {parameter "UserNameGIT"}>> __Download\bigfix-content\.git\config
//dos echo email = {parameter "UserEmailGIT"}>> __Download\bigfix-content\.git\config

waithidden cmd /C "{pathname of download folder}\bigfix-content\git.lnk" config --local user.email {parameter "UserEmailGIT"} >> {parameter "LogFile"} 2>&1
waithidden cmd /C "{pathname of download folder}\bigfix-content\git.lnk" config --local user.name {parameter "UserNameGIT"} >> {parameter "LogFile"} 2>&1

waithidden cmd /C "{pathname of download folder}\bigfix-content\git.lnk" add . >> {parameter "LogFile"} 2>&1
// --reuse-message will use the authorship of a previous commit so that it doesn't need configured
//waithidden cmd /C "{pathname of download folder}\bigfix-content\git.lnk" commit --verbose --reuse-message=9aafc31 >> __Download\git.log 2>&1

// http://examples.javacodegeeks.com/software-development/git-commit-amend-example/
//waithidden cmd /C "{pathname of download folder}\bigfix-content\git.lnk" commit --verbose --amend --only --message=test_amend >> __Download\git.log 2>&1

waithidden cmd /C "{pathname of download folder}\bigfix-content\git.lnk" commit --verbose --message=AutoBackup_{origin fixlet id of active action}_{id of active action}_{ (it - 1) of sum of (it as integer) of (active counts of it;first active counts of it) of active actions }_{concatenations "_" of substrings separated by " " of parameter "ExportTime"} >> {parameter "LogFile"} 2>&1

// DO NOT log the PUSH output because it contains User/Pass info in the URL
// https://git-scm.com/docs/git-push
waithidden cmd /C "{pathname of download folder}\bigfix-content\git.lnk" push
Success Criteria

This action will be considered successful when the applicability relevance evaluates to false.


Sharing

Social Media:
Share this page on Yammer

Comments

Log In or Register to leave comments!