├── .gitignore ├── CopyBackTrunk ├── README.md └── copybacktrunk.sh ├── CopyToSVN ├── README.md └── copytosvn.sh ├── LICENSE ├── MakeFogMobile ├── MainScript.sh ├── README.md └── install.sh ├── MonitorFogStorageNodes ├── MonitorNodes.sh └── README.md ├── PowershellModules ├── FogApi │ ├── Build.ps1 │ ├── FogApi │ │ ├── FogApi.psd1 │ │ ├── FogApi.psm1 │ │ ├── Private │ │ │ ├── Get-DynmicParam.ps1 │ │ │ └── Set-DynamicParams.ps1 │ │ ├── Public │ │ │ ├── Get-FogAssociatedSnapins.ps1 │ │ │ ├── Get-FogGroup.ps1 │ │ │ ├── Get-FogHost.ps1 │ │ │ ├── Get-FogHosts.ps1 │ │ │ ├── Get-FogInventory.ps1 │ │ │ ├── Get-FogLog.ps1 │ │ │ ├── Get-FogObject.ps1 │ │ │ ├── Get-FogServerSettings.ps1 │ │ │ ├── Get-FogSnapins.ps1 │ │ │ ├── Install-FogService.ps1 │ │ │ ├── Invoke-FogApi.ps1 │ │ │ ├── New-FogObject.ps1 │ │ │ ├── Remove-FogObject.ps1 │ │ │ ├── Remove-UsbMac.ps1 │ │ │ ├── Set-FogInventory.ps1 │ │ │ ├── Set-FogServerSettings.ps1 │ │ │ ├── Set-FogSnapins.ps1 │ │ │ ├── Start-FogSnapins.ps1 │ │ │ └── Update-FogObject.ps1 │ │ ├── Readme.md │ │ ├── Tools │ │ │ └── settings.json │ │ └── docs │ │ │ ├── Get-FogAssociatedSnapins.md │ │ │ ├── Get-FogGroup.md │ │ │ ├── Get-FogHost.md │ │ │ ├── Get-FogHosts.md │ │ │ ├── Get-FogInventory.md │ │ │ ├── Get-FogLog.md │ │ │ ├── Get-FogObject.md │ │ │ ├── Get-FogServerSettings.md │ │ │ ├── Get-FogSnapins.md │ │ │ ├── Install-FogService.md │ │ │ ├── Invoke-FogApi.md │ │ │ ├── New-FogObject.md │ │ │ ├── Remove-FogObject.md │ │ │ ├── Remove-UsbMac.md │ │ │ ├── Set-FogInventory.md │ │ │ ├── Set-FogServerSettings.md │ │ │ ├── Set-FogSnapins.md │ │ │ ├── Start-FogSnapins.md │ │ │ ├── Update-FogObject.md │ │ │ ├── about_FogApi.md │ │ │ └── en-us │ │ │ ├── FogApi-help.xml │ │ │ ├── about_FogApi.help.txt │ │ │ └── fogapi.dev-help.xml │ └── Readme.md ├── Readme.md ├── Snippets │ └── Fog-Commands.psm1 └── StartLayoutCreator │ ├── StartLayoutCreator.psd1 │ ├── StartLayoutCreator.psm1 │ └── readme.md ├── README.md ├── RenumberImageIDs ├── README.md └── renumberImageIDs.sh ├── RenumberSnapinIDs ├── README.md └── renumberSnapinIDs.sh ├── StorageNodeManagementTools ├── README.md ├── initialFogGitPull.sh ├── installPackage.sh ├── rebootNodes.sh ├── removePackage.sh ├── settings.sh ├── updateNodeFOGs.sh └── updateNodeOSs.sh ├── delete-extra-macs-on-host ├── README.md └── delete-extra-macs.sh ├── delete-network-printers ├── README.md └── deleteNetworkPrinters.ps1 ├── exportFromDB ├── README.md └── exportTableToCSV.sh ├── external_reporting └── README.md ├── fog-aws-testing └── README.md ├── fog-cli ├── README.md ├── cli-init └── fog-config ├── fog-libvirtd-testing ├── .gitignore ├── README.md ├── apache2.conf ├── cancelTasks.sh ├── captureImage.sh ├── createSnapshots.sh ├── customCommand.sh ├── deleteSnapshots.sh ├── deployImage.sh ├── getImageLogs.sh ├── getTaskStatus.sh ├── getTestServerReady.sh ├── green.png ├── installBranch.sh ├── orange.png ├── postdownload.sh ├── postinit.sh ├── rebootVMs.sh ├── red.png ├── restoreSnapshots.sh ├── setTestHostImages.sh ├── settings.sh ├── shutdownTestServer.sh ├── shutdownVMs.sh ├── smb.conf ├── test_all.sh ├── test_imaging.sh ├── test_install.sh ├── upCheck.sh ├── updateNodeFOGs.sh ├── updateNodeOSs.sh └── updateSystems.sh ├── troubleshootingTools ├── README.md ├── monitor-missing-primary-mac.sh └── troubleshoot.sh └── updateIP ├── README.md ├── functions.sh └── updateIP.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .terraform 2 | terraform.tfstate 3 | terraform.tfstate.backup 4 | .terraform.lock.hcl 5 | -------------------------------------------------------------------------------- /CopyBackTrunk/README.md: -------------------------------------------------------------------------------- 1 | ### AUTHOR: Tom Elliott 2 | --- 3 | 4 | * All this does is copy the files from the trunk web folder to the real document root. 5 | * It can take an argument to tell what path of trunk else it will assume ~/trunk. 6 | -------------------------------------------------------------------------------- /CopyBackTrunk/copybacktrunk.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | path=$1 3 | configpath=$2 4 | [[ -z $path || ! -e "$HOME/$path" ]] && path="$HOME/fogproject" 5 | [[ -z $configpath || ! -e "$configpath" ]] && configpath="$HOME/config.class.php" 6 | [[ ! -e "$configpath" && -e /var/www/fog/lib/fog/config.class.php ]] && cp /var/www/fog/lib/fog/config.class.php $configpath 7 | [[ ! -e $configpath ]] && { 8 | echo "No configuration file available. Please make sure this file exists" 9 | exit 1 10 | } 11 | rsync -a --no-links -heP --delete $path/packages/web/ /var/www/fog/ 12 | cp $configpath /var/www/fog/lib/fog/config.class.php 13 | chown -R apache:apache /var/www/fog 14 | chown -R fogproject:apache /var/www/fog/service/ipxe 15 | -------------------------------------------------------------------------------- /CopyToSVN/README.md: -------------------------------------------------------------------------------- 1 | ### AUTHOR: Tom Elliott 2 | --- 3 | 4 | * All this does is take my files as I have edited them and copies them to my trunk directory for subversion/svn. 5 | * The extra “trunk2” stuff you see is for btsync when that was running. 6 | * If I call it as copytosvn git it will do the same as for trunk, but to only the git. This was added due to sourceforge being down last year. 7 | -------------------------------------------------------------------------------- /CopyToSVN/copytosvn.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Script perform copying of data. 3 | 4 | # Prints dots to a defined set. 5 | # Arguments: 6 | # $1 The string to pad right the dots. 7 | dots() { 8 | local string="$1" 9 | local pad=$(printf "%0.1s" "."{1..60}) 10 | printf " * %s%*.*s" "${string}" 0 $((60-${#string})) "${pad}" 11 | } 12 | 13 | # If error sent is not 0 exit from the 14 | # program and report failed. 15 | # Arguments: 16 | # $1 The errorcode to test. 17 | errorStat() { 18 | local error=$1 19 | if [[ ! $error -eq 0 ]]; then 20 | echo "Failed" 21 | exit 1 22 | fi 23 | echo "OK" 24 | } 25 | 26 | # Performs psr fixing of the files. 27 | # Arguments: 28 | # $1 The path check. 29 | psrfix() { 30 | local path="$1" 31 | [[ -z $path || ! -e $path ]] && errorStat 1 32 | dots "Updating php-cs-fixer" 33 | /usr/local/bin/php-cs-fixer self-update >/dev/null 2>&1 34 | errorStat "$?" 35 | dots "Fixing PSR Structures in php" 36 | /usr/local/bin/php-cs-fixer fix ${path} --rules=@PSR2 >/dev/null 2>&1 37 | echo "OK" 38 | } 39 | 40 | # Update the trunk files. 41 | # Arguments: 42 | # $1 Test variable for full or branch. 43 | trunkUpdate() { 44 | local testvar=$1 45 | local cwd=$(pwd) 46 | [[ $testvar == 'full' || -z $testvar ]] && testvar="" 47 | cd $HOME/fogproject 48 | dots "Updating GIT Directory" 49 | /usr/bin/git checkout $testvar >/dev/null 2>&1 50 | /usr/bin/git pull >/dev/null 2>&1 51 | errorStat "$?" 52 | } 53 | 54 | # Updates the version numbers. 55 | # Arguments: 56 | # $1 The second is branch or typed as full. 57 | versionUpdate() { 58 | local testvar=$1 59 | [[ $testvar == full ]] && channel="Stable" 60 | dots "Updating Version in File" 61 | local gitbranch=$(git branch | awk '/*/ {print $2}') 62 | local gitcom=$(git rev-list --tags --no-walk --max-count=1) 63 | local gitcount=$(git rev-list ${gitcom}..HEAD --count) 64 | local branchon=$(echo ${gitbranch} | awk -F'-' '{print $1}') 65 | local branchend=$(echo ${gitbranch} | awk -F'-' '{print $2}') 66 | local verbegin="" 67 | case $branchon in 68 | dev) 69 | verbegin="$(git describe --tags ${gitcom})." 70 | channel="Patches" 71 | ;; 72 | working) 73 | verbegin="${branchend}.0-beta." 74 | channel="Beta" 75 | ;; 76 | master) 77 | [[ -z $trunkver ]] && trunkver="$(git describe --tags ${gitcom})" 78 | channel="Release" 79 | ;; 80 | rc) 81 | verbegin="rc-${branchend}." 82 | channel="Release Candidate" 83 | ;; 84 | esac 85 | [[ -z $trunkver ]] && trunkversion="${verbegin}${gitcount}" || trunkversion=${trunkver} 86 | sed -i "s/define('FOG_VERSION'.*);/define('FOG_VERSION', '$trunkversion');/g" $HOME/fogproject/packages/web/lib/fog/system.class.php >/dev/null 2>&1 87 | [[ -z $channel ]] && channel="Alpha" 88 | sed -i "s/define('FOG_CHANNEL'.*);/define('FOG_CHANNEL', '$channel');/g" $HOME/fogproject/packages/web/lib/fog/system.class.php >/dev/null 2>&1 89 | errorStat $? 90 | } 91 | 92 | copyFilesToTrunk() { 93 | local testvar=$1 94 | local path='$HOME/fogproject/packages/web/' 95 | dots "Removing any ~ files." 96 | find /var/www/fog/ -type f -name "*~" -exec rm -rf {} \; >/dev/null 2>&1 97 | errorStat $? 98 | dots "Copying files to git" 99 | rsync -a --no-links -heP --exclude maintenance --delete /var/www/fog/ $HOME/fogproject/packages/web >/dev/null 2>&1 100 | errorStat $? 101 | dots "Cleaning up" 102 | rm -rf $HOME/fogproject/packages/web/lib/fog/config.class.php >/dev/null 2>&1 103 | rm -rf $HOME/fogproject/packages/web/management/other/cache/* >/dev/null 2>&1 104 | rm -rf $HOME/fogproject/packages/web/management/other/ssl >/dev/null 2>&1 105 | rm -rf $HOME/fogproject/packages/web/status/injectHosts.php >/dev/null 2>&1 106 | find $HOME/fogproject/ -type f -name "*~" -exec rm -rf {} \; >/dev/null 2>&1 107 | [[ $testvar == 'full' ]] && \ 108 | sed -i 's/^fullrelease=.*$/fullrelease="'${trunkver}'"/g' $HOME/fogproject/bin/installfog.sh || \ 109 | sed -i 's/^fullrelease=.*$/fullrelease="0"/g' $HOME/fogproject/bin/installfog.sh 110 | errorStat $? 111 | } 112 | 113 | updateLanguage() { 114 | xgettext --language=PHP --from-code=UTF-8 --output="$HOME/fogproject/packages/web/management/languages/messages.pot" --omit-header --no-location $(find $HOME/fogproject/packages/web/ -name "*.php") 115 | msgcat --sort-output -o "$HOME/fogproject/packages/web/management/languages/messages.pot" "$HOME/fogproject/packages/web/management/languages/messages.pot" 116 | for PO_FILE in $(find $HOME/fogproject/packages/web/management/languages/ -type f -name *.po); do 117 | msgmerge --update --backup=none $PO_FILE $HOME/fogproject/packages/web/management/languages/messages.pot 2>/dev/null >/dev/null 118 | msgcat --sort-output -o $PO_FILE $PO_FILE 119 | done 120 | } 121 | 122 | [[ -n $psrfix ]] && psrfix "/var/www/fog" 123 | trunkUpdate $* 124 | [[ $3 == update ]] && exit 0 125 | #dots "Update language po/pot files" 126 | #foglanguage.sh >/dev/null 2>&1 127 | #errorStat $? 128 | copyFilesToTrunk $* 129 | updateLanguage $* 130 | versionUpdate $* 131 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 FOG Project 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MakeFogMobile/README.md: -------------------------------------------------------------------------------- 1 | ### Author: Wayne Workman 2 | --- 3 | 4 | This small project makes FOG mobile. 5 | 6 | With this project, you may configure hardware of your choosing to use DHCP from wherever it's hooked up. Install FOG on this sytem, then install this project. This project will detect if the mobile FOG Server's IPv4 address has changed or not. If it detects change, this project will re-configure the FOG server's IP Address and also re-configure dnsmasq in ProxyDHCP mode. This enables you to carry your mobile FOG server into any network to be plugged up and just begin imaging minutes after the server boots up without changing anything manually on the server or on the network. 7 | 8 | 9 | The project should work fine on: 10 | * Red Hat 7 11 | * CentOS 7 12 | * Fedora 19+ 13 | * Ubuntu 16 14 | * Debian 8 15 | * Raspbian Jessie+ 16 | 17 | 18 | Thanks to forums.fogproject.org @sudburr for doing the initial work. 19 | Expanded & Made better by forums.fogproject.org @Wayne-Workman 20 | Thanks to Tom Elliott for helping with cross-platform compatibility. 21 | 22 | Please direct inqueries about this to the fog forums. 23 | 24 | 25 | What triggers this software to correct the FOG Server's IP address and reconfigure dnsmasq is: 26 | If the field "ipaddress" inside of /opt/fog/.fogsettings does not match the actual IPv4 address on the local interface. 27 | 28 | The installation script does install dnsmasq too, and adds it to FOG's packages list inside .fogsettings 29 | 30 | The script creates a root cron event that runs the main script every 3 minutes - this is what automatically keeps the IP settings updated. 31 | 32 | This small project and it's files and documentation are subject to the limitations of the fog community scripts license. 33 | 34 | There are some settings that can be modified in the main script - these are towards the top of the file. An important note is that the storage node name in the script must match what the real name is in the FOG Server. The script is already set to the default value. 35 | 36 | -------------------------------------------------------------------------------- /MakeFogMobile/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #---- Set variables ----# 4 | 5 | echo "Installing, please wait..." 6 | 7 | currentDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 8 | utilsDir=/opt/fog/utils 9 | targetDir=/opt/fog/utils/MakeFogMobile 10 | fogsettings=/opt/fog/.fogsettings 11 | packages="$(grep 'packages=' $fogsettings | cut -d \' -f2 )" 12 | 13 | #---- Check if FOG is installed ----# 14 | 15 | if [[ ! -f $fogsettings ]]; then 16 | echo "$fogsettings file not found." 17 | echo Please install FOG first. 18 | exit 19 | fi 20 | 21 | #---- Check if this is running as root ----* 22 | 23 | currentUser=$(whoami) 24 | if [[ "$currentUser" != "root" ]]; then 25 | echo "I am ${currentUser}, exiting." 26 | exit 27 | fi 28 | 29 | 30 | 31 | #---- Create directory and copy files ----# 32 | 33 | #Correcting for FOG sourceforge revision 4580 where the utils directory is no longer created. 34 | if [[ ! -d $utilsDir ]]; then 35 | mkdir $utilsDir 36 | fi 37 | 38 | 39 | #If the target directory already exists, delete it. Then remake it. 40 | if [[ -d $targetDir ]]; then 41 | rm -rf $targetDir 42 | fi 43 | mkdir $targetDir 44 | 45 | cp $currentDir/README.md $targetDir/README.md 46 | cp $currentDir/MainScript.sh $targetDir/MakeFogMobile.sh 47 | 48 | 49 | #make the main script executable. 50 | chmod +x $targetDir/MakeFogMobile.sh 51 | 52 | #Check if dnsmasq is installed. If not, try to install it. 53 | 54 | dnsmasq=$(command -v dnsmasq) 55 | 56 | systemctl=$(command -v systemctl) 57 | service=$(command -v service) 58 | 59 | if [[ ! -z "$systemctl" ]]; then 60 | dnsmasqStatus=$(systemctl status dnsmasq >/dev/null 2>&1) 61 | elif [[ ! -z "$service" ]]; then 62 | dnsmasqStatus=$(service dnsmasq status >/dev/null 2>&1) 63 | else 64 | echo "Don't know how to check dnsmasq service status." 65 | echo "Going to try to install dnsmasq." 66 | dnsmasqStatus="1" 67 | fi 68 | 69 | 70 | 71 | 72 | if [[ -z "$dnsmasq" || "$dnsmasqStatus" != "0" ]]; then 73 | 74 | yum=$(command -v yum) 75 | dnf=$(command -v dnf) 76 | aptget=$(command -v apt-get) 77 | 78 | if [[ -e "$yum" ]]; then 79 | yum install dnsmasq -y >/dev/null 2>&1 80 | elif [[ -e "$dnf" ]]; then 81 | dnf install dnsmasq -y >/dev/null 2>&1 82 | elif [[ -e "$aptget" ]]; then 83 | apt-get install dnsmasq -y >/dev/null 2>&1 84 | else 85 | echo "Could not find a repo manager to install dnsmasq, quitting." 86 | exit 1 87 | fi 88 | fi 89 | 90 | #---- Create the cron event ----# 91 | crontab -l -u root | grep -v PATH | crontab -u root - 92 | newline=$PATH 93 | (crontab -l -u root; echo "PATH=$newline") | crontab - >/dev/null 2>&1 94 | 95 | 96 | crontab -l -u root | grep -v MakeFogMobile.sh | crontab -u root - 97 | # */3 for every three minutes. 98 | newline="*/3 * * * * $targetDir/MakeFogMobile.sh" 99 | (crontab -l -u root; echo "$newline") | crontab - >/dev/null 2>&1 100 | 101 | echo "Finished." 102 | -------------------------------------------------------------------------------- /MonitorFogStorageNodes/MonitorNodes.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | webFile="/var/www/html/nodestatus.html" #Where to put the web document. 3 | PageAutoRefreshTime="15" #How often the web document should auto-refresh. 4 | WaitTime="15" #The amount of time in seconds that a node has to respond. You can use decimals, such as "0.3" or "2.5" 5 | 6 | #-----Get command paths-----# 7 | printf=$(command -v printf) 8 | ping=$(command -v ping) 9 | mysql=$(command -v mysql) 10 | date=$(command -v date) 11 | 12 | #----- MySQL Credentials -----# 13 | snmysqluser="" 14 | snmysqlpass="" 15 | snmysqlhost="" 16 | # If user and pass is blank, leave just a set of double quotes like "" 17 | # if the db is local, set the host to just double quotes "" or "127.0.0.1" or "localhost" 18 | 19 | 20 | 21 | 22 | #----- Queries ------# 23 | getHostnames="SELECT \`ngmHostname\`, \`ngmMemberName\` FROM \`nfsGroupMembers\`" 24 | 25 | 26 | 27 | #----- Build mysql options -----# 28 | options="-sN" 29 | if [[ $snmysqlhost != "" ]]; then 30 | options="$options -h$snmysqlhost" 31 | fi 32 | if [[ $snmysqluser != "" ]]; then 33 | options="$options -u$snmysqluser" 34 | fi 35 | if [[ $snmysqlpass != "" ]]; then 36 | options="$options -p$snmysqlpass" 37 | fi 38 | options="$options -D fog -e" 39 | 40 | 41 | 42 | #------- HTML pieces ------# 43 | htmlHead="\n\n\n\n\nNode Status\n\n\n\n" 44 | htmlHeading="

FOG Storage Node Status

\n
\n" 45 | waitMessage="
\nCurrent Wait Time for ping response is set to $WaitTime seconds.\n
\n
\n" 46 | online="Online!\n
\n" 47 | offline="Offline!\n
\n" 48 | rightNow="
Last Updated: $( $date )
\n" 49 | htmlFoot="\n\n" 50 | 51 | 52 | #---- Start wring html doc, header and other info. ------# 53 | 54 | $printf "$htmlHead" > $webFile 55 | $printf "$htmlHeading" >> $webFile 56 | $printf "$waitMessage" >> $webFile 57 | $printf "$rightNow" >> $webFile 58 | 59 | 60 | #query database for list of nodes and names, loop through each. 61 | $mysql $options "$getHostnames" | while read ngmHostname ngmMemberName; do 62 | #Ping each one. 63 | $ping -i $WaitTime -c 1 $ngmHostname > /dev/null 2>&1 64 | if [[ $? -eq 0 ]]; then 65 | #if ping succeeds, it's online. 66 | $printf "$ngmMemberName is $online" >> $webFile 67 | else 68 | #if ping fails, it's offline. 69 | $printf "$ngmMemberName is $offline" >> $webFile 70 | fi 71 | #end loop 72 | done 73 | #write footer. 74 | $printf "$htmlFoot" >> $webFile 75 | 76 | 77 | -------------------------------------------------------------------------------- /MonitorFogStorageNodes/README.md: -------------------------------------------------------------------------------- 1 | ### Monitor FOG Storage Nodes 2 | ## Author: Wayne Workman 3 | 4 | --- 5 | 6 | This is a simple BASH script that aids in monitoring the online/offline status of many storage nodes. 7 | 8 | 9 | Place the MonitorNodes.sh file onto your main fog server. 10 | Leaving it in the cloned git repo is fine. 11 | 12 | 13 | Create a root crontab event. You will need to be root to do this. 14 | You can switch to root with: 15 | 16 | `sudo -i` 17 | 18 | Then enter into root's crontab with: 19 | 20 | `crontab -e` 21 | 22 | 23 | Add this line to the file to run the script every minute. 24 | 25 | `* * * * * /root/MonitorNodes.sh` 26 | 27 | Or this to run every 3 minutes: 28 | 29 | `*/3 * * * * /root/MonitorNodes.sh` 30 | 31 | The script will ping all fog storage nodes. 32 | If they respond within the defined WaitTime, they are marked as enabled in the DB. 33 | If they do not respond within the defined WaitTime, they are marked as disabled in the DB. 34 | 35 | Also, a simple web report is generated that lists all storage node status. 36 | You can view it by navigating to the below address, where x.x.x.x is your main fog server's IP. 37 | 38 | `x.x.x.x\nodestatus.html` 39 | 40 | This tool is licensed under the fog community scripts license. 41 | 42 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/Build.ps1: -------------------------------------------------------------------------------- 1 | 2 | <#PSScriptInfo 3 | 4 | .VERSION 1.0.0.0 5 | 6 | .GUID 473e8205-f9ee-4185-9daa-096fb36cf0b6 7 | 8 | .AUTHOR JJ Fullmer 9 | 10 | .COMPANYNAME Arrowhead Dental Lab 11 | 12 | .COPYRIGHT 2019 13 | 14 | .TAGS 15 | 16 | .LICENSEURI 17 | 18 | .PROJECTURI 19 | 20 | .ICONURI 21 | 22 | .EXTERNALMODULEDEPENDENCIES 23 | 24 | .REQUIREDSCRIPTS 25 | 26 | .EXTERNALSCRIPTDEPENDENCIES 27 | 28 | .RELEASENOTES 29 | 30 | 1.0.0.0 31 | Updated script to proper format 32 | 33 | .PRIVATEDATA 34 | 35 | #> 36 | 37 | #Requires -Module @{ ModuleName = 'PlatyPS'; ModuleVersion = '0.14.0' } 38 | 39 | <# 40 | 41 | .DESCRIPTION 42 | Script to manually build the module, this will install the third party platyps module 43 | This is a light version of the build script I use, but it should be enough for basic testing 44 | of new features. The original contains propietary code that can't be shared. 45 | 46 | #> 47 | [CmdletBinding()] 48 | Param() 49 | 50 | $moduleName = 'FogApi' 51 | $modulePath = "$PSScriptRoot\$moduleName"; 52 | 53 | mkdir $modulePath -EA 0; 54 | mkdir "$modulePath\tools" -EA 0; 55 | mkdir "$modulePath\docs" -EA 0; 56 | mkdir "$modulePath\lib" -EA 0; 57 | mkdir "$modulePath\bin" -EA 0; 58 | mkdir "$modulePath\Public" -EA 0; 59 | mkdir "$modulePath\Private" -EA 0; 60 | mkdir "$modulePath\Classes" -EA 0; 61 | 62 | #update documentation 63 | 64 | $ses = New-PsSession; 65 | $docsPth = "$modulePath\docs" 66 | 67 | Invoke-Command -Session $ses -ScriptBlock { 68 | $moduleName = $Using:moduleName 69 | $modulePath = $Using:modulePath 70 | $docsPth = $Using:docsPth 71 | New-Dir $docsPth; 72 | Remove-Module $moduleName -force -EA 0; 73 | Import-Module "$modulePath\$moduleName.psm1" -force; 74 | #import any classes so they are recognized and do it twice to resolve classes with dependencies 75 | $classPth = "$modulePath\classes"; 76 | $classPth | Get-ChildItem | ForEach-Object { Import-Module $_.Fullname -force -EA 0;} 77 | $classPth | Get-ChildItem | ForEach-Object { Import-Module $_.Fullname -force;} 78 | # Remove old markdown files 79 | $docsPth | Get-ChildItem -Filter '*.md' | Where-Object Name -NotMatch 'about_*' | Remove-Item -Force; 80 | New-MarkdownHelp -module $moduleName -Force -OutputFolder $docsPth; 81 | try { 82 | New-ExternalHelp -Path $docsPth -OutputPath "$docsPth\en-us" -Force; 83 | } catch { 84 | Write-Warning "There was an error creating the external help from the markdown. $($error) Removing current external help and trying again" 85 | Remove-Item -Force -Recurse "$docsPth\en-us"; 86 | New-Dir "$docsPth\en-us" 87 | New-ExternalHelp -Path $docsPth -OutputPath "$docsPth\en-us" -EA 0 -Force; 88 | } 89 | } 90 | 91 | $ses | Remove-PsSession; 92 | 93 | $PublicFunctions = Get-ChildItem "$modulePath\Public" -Recurse -Filter '*.ps1' -EA 0; 94 | $Classes = Get-ChildItem "$modulePath\Classes" -Recurse -Filter '*.ps1' -EA 0; 95 | $PrivateFunctions = Get-ChildItem "$modulePath\Private" -Recurse -Filter '*.ps1' -EA 0; 96 | mkdir "$PSSCriptRoot\ModuleBuild" -EA 0; 97 | $buildPth = "$PSSCriptRoot\ModuleBuild"; 98 | $moduleFile = "$buildPth\$moduleName.psm1"; 99 | 100 | # Create the build output folder 101 | if (Test-Path $buildPth) { 102 | Remove-Item $buildPth -force -recurse; 103 | } 104 | New-Dir 'C:\ModuleBuild' | Out-Null; 105 | New-Dir $buildPth | Out-Null; 106 | 107 | New-Item $moduleFile -Force | Out-Null; 108 | Copy-Item "$modulePath\$moduleName.psd1" "$buildPth\$moduleName.psd1"; 109 | Copy-Item "$modulePath\docs\en-us" "$buildPth\en-us" -Recurse -Exclude '*.md'; 110 | Add-Content -Path $moduleFile -Value "`$PSModuleRoot = `$PSScriptRoot"; 111 | if ((Get-ChildItem "$modulePath\lib").count -gt 0) { 112 | Copy-Item "$modulePath\lib" "$buildPth\lib" -Recurse; 113 | Add-Content -Path $moduleFile -Value "`$lib = `"`$PSModuleRoot\lib`""; 114 | } 115 | if ((Get-ChildItem "$modulePath\bin").count -gt 0) { 116 | Copy-Item "$modulePath\bin" "$buildPth\bin" -Recurse; 117 | Add-Content -Path $moduleFile -Value "`$bin = `"`$PSModuleRoot\bin`""; 118 | } 119 | Copy-Item "$modulePath\tools" "$buildPth\tools" -Recurse; 120 | Add-Content -Path $moduleFile -Value "`$tools = `"`$PSModuleRoot\tools`""; 121 | 122 | 123 | #Build the psm1 file 124 | 125 | 126 | #Add Classes 127 | if ($null -ne $Classes) { 128 | 129 | $Classes | % { 130 | Add-Content -Path $moduleFile -Value (Get-Content $_.FullName); 131 | } 132 | 133 | } 134 | # Add-PublicFunctions 135 | Add-Content -Path $moduleFile -Value $heading 136 | # $PublicFunctions; 137 | $PublicFunctions | ForEach-Object { # Replace the comment block with external help link 138 | $rawContent = (Get-Content $_.FullName -Raw); 139 | $commentStartIdx = $rawContent.indexOf('<#'); 140 | if ($commentStartIdx -ge 0) { 141 | $commentEndIdx = $rawContent.IndexOf('#>'); 142 | $commentLength = $commentEndIdx - ($commentStartIdx-2); #-2 to adjust for the # in front of > and the index starting at 0 143 | $comment = $rawContent.Substring($commentStartIdx,$commentLength); 144 | $newComment = "# .ExternalHelp $moduleName-help.xml" 145 | $Function = $rawContent.Replace($comment,$newComment); 146 | } else { 147 | $Function = $rawContent; 148 | } 149 | Add-Content -Path $moduleFile -Value $Function 150 | } 151 | #Add Private Functions 152 | if ($null -ne $PrivateFunctions) { 153 | $PrivateFunctions | % { 154 | Add-Content -Path $moduleFile -Value (Get-Content $_.FullName); 155 | } 156 | } 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/FogApi.psm1: -------------------------------------------------------------------------------- 1 | $PSModuleRoot = $PSScriptRoot 2 | $tools = "$PSModuleRoot\tools" 3 | $lib = "$PSModuleRoot\lib" 4 | $bin = "$PSModuleRoot\bin" 5 | $PublicFunctions = @( Get-ChildItem -Path "$PSScriptRoot/Public/*.ps1" -ErrorAction SilentlyContinue ) 6 | $PrivateFunctions = @( Get-ChildItem -Path "$PSScriptRoot/Private/*.ps1" -ErrorAction SilentlyContinue ) 7 | 8 | 9 | foreach ($file in @($PublicFunctions + $PrivateFunctions)) { 10 | try { 11 | . $file.FullName 12 | } 13 | catch { 14 | $exception = ([System.ArgumentException]"Function not found") 15 | $errorId = "Load.Function" 16 | $errorCategory = 'ObjectNotFound' 17 | $errorTarget = $file 18 | $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget 19 | $errorItem.ErrorDetails = "Failed to import function $($file.BaseName)" 20 | throw $errorItem 21 | } 22 | } 23 | Export-ModuleMember -Function $PublicFunctions.BaseName -Alias * 24 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/Private/Get-DynmicParam.ps1: -------------------------------------------------------------------------------- 1 | function Get-DynmicParam { 2 | <# 3 | .SYNOPSIS 4 | Gets the dynamic parameter for the main functions 5 | 6 | .DESCRIPTION 7 | Dynamically sets the correct tab completeable validate set for the coreobject, coretaskobject, coreactivetaskobject, or string to search 8 | 9 | .PARAMETER paramName 10 | the name of the parameter being dynamically set within the validate set 11 | 12 | .PARAMETER position 13 | the position to put the dynamic parameter in 14 | 15 | #> 16 | 17 | [CmdletBinding()] 18 | param ( 19 | [Parameter(Position=0)] 20 | [ValidateSet('coreObject','coreTaskObject','coreActiveTaskObject','stringToSearch')] 21 | [string]$paramName, 22 | $position=1 23 | ) 24 | begin { 25 | #initilzie objects 26 | $attributes = New-Object Parameter; #System.Management.Automation.ParameterAttribute; 27 | $attributeCollection = New-Object -Type System.Collections.ObjectModel.Collection[System.Attribute] 28 | # $paramDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary 29 | # Set attributes 30 | $attributes.Position = $position; 31 | $attributes.Mandatory = $true; 32 | 33 | $attributeCollection.Add($attributes) 34 | 35 | $coreObjects = @( 36 | "clientupdater", "dircleaner", "greenfog", "group", "groupassociation", 37 | "history", "hookevent", "host", "hostautologout", "hostscreensetting", "image", 38 | "imageassociation", "imagepartitiontype", "imagetype", "imaginglog", "inventory", "ipxe", 39 | "keysequence", "macaddressassociation", "module", "moduleassociation", "multicastsession", 40 | "multicastsessionsassociation", "nodefailure", "notifyevent", "os", "oui", "plugin", 41 | "powermanagement", "printer", "printerassociation", "pxemenuoptions", "scheduledtask", 42 | "service", "snapin", "snapinassociation", "snapingroupassociation", "snapinjob", 43 | "snapintask", "storagegroup", "storagenode", "task", "tasklog", "taskstate", "tasktype", 44 | "usercleanup", "usertracking", "virus" 45 | ); 46 | $coreTaskObjects = @("group", "host", "multicastsession", "snapinjob", "snapintask", "task"); 47 | $coreActiveTaskObjects = @("multicastsession", "scheduledtask", "snapinjob", "snapintask", "task"); 48 | } 49 | 50 | process { 51 | switch ($paramName) { 52 | coreObject { $attributeCollection.Add((New-Object ValidateSet($coreObjects)));} 53 | coreTaskObject {$attributeCollection.Add((New-Object ValidateSet($coreTaskObjects)));} 54 | coreActiveTaskObject {$attributeCollection.Add((New-Object ValidateSet($coreActiveTaskObjects)));} 55 | } 56 | $dynParam = New-Object System.Management.Automation.RuntimeDefinedParameter($paramName, [string], $attributeCollection); 57 | # $paramDictionary.Add($paramName, $dynParam); 58 | } 59 | end { 60 | return $dynParam; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/Private/Set-DynamicParams.ps1: -------------------------------------------------------------------------------- 1 | function Set-DynamicParams { 2 | <# 3 | .SYNOPSIS 4 | Sets the dynamic param dictionary 5 | 6 | .DESCRIPTION 7 | Sets dynamic parameters inside functions 8 | 9 | .PARAMETER type 10 | the type of parameter 11 | 12 | #> 13 | 14 | [CmdletBinding()] 15 | param ($type) 16 | $paramDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary; 17 | 18 | # Sub function for setting 19 | function Set-Param($paramName) { 20 | $param = Get-DynmicParam -paramName $paramName; 21 | $paramDictionary.Add($paramName, $param); 22 | } 23 | switch ($type) { 24 | object { Set-Param('coreObject');} 25 | objectactivetasktype { Set-Param('coreActiveTaskObject');} 26 | objecttasktype {Set-Param('coreTaskObject');} 27 | search {Set-Param('stringToSearch');} 28 | } 29 | return $paramDictionary; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/Public/Get-FogAssociatedSnapins.ps1: -------------------------------------------------------------------------------- 1 | function Get-FogAssociatedSnapins { 2 | <# 3 | .SYNOPSIS 4 | Returns list of all snapins associated with a hostid 5 | 6 | .DESCRIPTION 7 | Gives a full list of all snapins associated with a given host 8 | #> 9 | 10 | [CmdletBinding()] 11 | param ( 12 | $hostId=((Get-FogHost).id) 13 | ) 14 | 15 | process { 16 | $AllAssocs = (Invoke-FogApi -Method GET -uriPath snapinassociation).snapinassociations; 17 | $snapins = New-Object System.Collections.Generic.List[object]; 18 | # $allSnapins = Get-FogSnapins; 19 | $AllAssocs | Where-Object hostID -eq $hostID | ForEach-Object { 20 | $snapinID = $_.snapinID; 21 | $snapins.add((Invoke-FogApi -uriPath "snapin\$snapinID")) 22 | } 23 | return $snapins; 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/Public/Get-FogGroup.ps1: -------------------------------------------------------------------------------- 1 | function Get-FogGroup { 2 | <# 3 | .SYNOPSIS 4 | needs to return the group name of the group that isn't the everyone group 5 | will use groupassociation call to get group id then group id to get group name from group uriPath 6 | 7 | .DESCRIPTION 8 | requires the id of the host you want the groups that aren't the everyone group for 9 | #> 10 | [CmdletBinding()] 11 | param ( 12 | [int]$hostId 13 | ) 14 | 15 | begin { 16 | [bool]$found = $false; 17 | Write-Verbose 'Getting all fog group associations...'; 18 | $groupAssocs = (Invoke-FogApi -uriPath groupassociation).groupassociations; 19 | Write-Verbose 'Getting all fog groups...'; 20 | $groups = (Invoke-FogApi -uriPath group).groups; 21 | } 22 | 23 | process { 24 | Write-Verbose "Finding group association for hostid of $hostId"; 25 | $hostGroups = $groupAssocs | Where-Object hostID -eq $hostId; 26 | Write-Verbose "filtering out everyone and touchscreen group"; 27 | $hostGroups = $hostGroups | Where-Object groupID -ne 3; #groupID 3 is the everyone group, don't include that 28 | $hostGroups = $hostGroups | Where-Object groupID -ne 11; #groupID 11 is the wkstouchscreens group, don't include that either 29 | 30 | Write-Verbose "finding group that matches group id of $hostGroups..."; 31 | $group = $groups | Where-Object id -eq $hostGroups.groupID; 32 | Write-Verbose 'checking if group was found...'; 33 | if($null -ne $group -AND $group -ne "") { $found = $true; Write-Verbose 'group found!'} 34 | } 35 | 36 | end { 37 | if($found){ 38 | return $group; 39 | } 40 | return $found; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/Public/Get-FogHost.ps1: -------------------------------------------------------------------------------- 1 | function Get-FogHost { 2 | <# 3 | .SYNOPSIS 4 | Gets the object of a specific fog host 5 | 6 | .DESCRIPTION 7 | Searches a new or existing object of hosts for a specific host (or hosts) with search options of uuid, hostname, or mac address 8 | if no search terms are specified then it gets the search terms from your host that is making the request and tries to find your 9 | computer in fog 10 | 11 | .PARAMETER uuid 12 | the uuid of the host 13 | 14 | .PARAMETER hostName 15 | the hostname of the host 16 | 17 | .PARAMETER macAddr 18 | a mac address linked to the host 19 | 20 | .PARAMETER hosts 21 | defaults to calling Get-FogHosts but if you already have that in an object you can pass it here to speed up processing 22 | 23 | .EXAMPLE 24 | Get-FogHost -hostName MewoMachine 25 | This would return the fog details of a host named MeowMachine in your fog instance 26 | 27 | .EXAMPLE 28 | Get-FogHost 29 | If you specify no param it will return your current host from fog 30 | 31 | .LINK 32 | Get-FogHosts 33 | 34 | .LINK 35 | Get-FogObject 36 | 37 | 38 | #> 39 | 40 | [CmdletBinding()] 41 | param ( 42 | [string]$uuid, 43 | [string]$hostName, 44 | [string]$macAddr, 45 | $hosts = (Get-FogHosts) 46 | ) 47 | 48 | begin { 49 | [bool]$found = $false; 50 | Write-Verbose 'Checking for passed variables' 51 | if (!$uuid -and !$hostName -and !$macAddr) { 52 | Write-Verbose 'no params given, getting current computer variables'; 53 | $compSys = (Get-WmiObject Win32_ComputerSystemProduct); 54 | if ($compSys.UUID -notmatch "12345678-9012-3456-7890-abcdefabcdef" ) { 55 | $uuid = $compSys.UUID; 56 | } else { 57 | $uuid = ($compSys.Qualifiers | Where-Object Name -match 'UUID' | Select-Object -ExpandProperty Value); 58 | } 59 | $macAddr = ((Get-NetAdapter | Select-Object MacAddress)[0].MacAddress).Replace('-',':'); 60 | $hostName = $(hostname); 61 | } 62 | Write-Verbose 'getting all hosts to search...'; 63 | Write-Verbose "search terms: uuid is $uuid, macAddr is $macAddr, hostname is $hostName"; 64 | } 65 | 66 | process { 67 | Write-Verbose 'finding host in hosts'; 68 | [bool]$found = $false; 69 | $hostObj = $hosts | Where-Object { 70 | ($uuid -ne "" -AND $_.inventory.sysuuid -eq $uuid) -OR ` 71 | ($hostName -ne "" -AND $_.name -eq $hostName) -OR ` 72 | ($macAddr -ne "" -AND $_.macs -contains $macAddr); 73 | if ($uuid -ne "" -AND $_.inventory.sysuuid -eq $uuid) { 74 | Write-Verbose "$($_.inventory.sysuuid) matches the uuid $uuid`! host found"; 75 | $found = $true; 76 | } 77 | if ($macAddr -ne "" -AND $_.macs -contains $macAddr) { 78 | Write-Verbose "$($_.macs) matches the macaddress $macAddr`! host found"; 79 | $found = $true; 80 | } 81 | if ($hostName -ne "" -AND $_.name -eq $hostName) { 82 | Write-Verbose "$($_.name) matches the hostname $hostName`! host found"; 83 | $found = $true; 84 | } 85 | } 86 | } 87 | 88 | end { 89 | if ($found){ 90 | return $hostObj; 91 | } 92 | return $found; #return false if host not found 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/Public/Get-FogHosts.ps1: -------------------------------------------------------------------------------- 1 | function Get-FogHosts { 2 | <# 3 | .SYNOPSIS 4 | Gets all fog hosts 5 | 6 | .DESCRIPTION 7 | helper function for get-fogobject that gets all host objects 8 | 9 | .EXAMPLE 10 | Get-FogHosts 11 | 12 | #> 13 | 14 | [CmdletBinding()] 15 | param ( 16 | 17 | ) 18 | 19 | begin { 20 | Write-Verbose "getting fog hosts" 21 | } 22 | 23 | process { 24 | $hosts = Get-FogObject -type Object -CoreObject host | Select-Object -ExpandProperty hosts 25 | } 26 | 27 | end { 28 | return $hosts; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/Public/Get-FogInventory.ps1: -------------------------------------------------------------------------------- 1 | function Get-FogInventory { 2 | <# 3 | .SYNOPSIS 4 | Gets a local computer's inventory with wmi and returns 5 | a json object that can be used to set fog inventory 6 | 7 | .DESCRIPTION 8 | Uses various wmi classes to get every possible inventory item to set in fog 9 | 10 | .PARAMETER hostObj 11 | the host to get the model of the inventory object from 12 | 13 | #> 14 | 15 | [CmdletBinding()] 16 | param ( 17 | $hostObj = (Get-FogHost) 18 | ) 19 | 20 | begin { 21 | $comp = Get-WmiObject -Class Win32_ComputerSystem; 22 | $compSys = Get-WmiObject -Class Win32_ComputerSystemProduct; 23 | $cpu = Get-WmiObject -Class Win32_processor; 24 | $bios = Get-WmiObject -Class Win32_Bios; 25 | $hdd = Get-WmiObject -Class Win32_DiskDrive | Where-Object DeviceID -match '0'; #get just drive 0 in case of multiple drives 26 | $baseBoard = Get-WmiObject -Class Win32_BaseBoard; 27 | $case = Get-WmiObject -Class Win32_SystemEnclosure; 28 | $info = Get-ComputerInfo; 29 | } 30 | 31 | process { 32 | $hostObj.inventory.hostID = $hostObj.id; 33 | # $hostObj.inventory.primaryUser = 34 | # $hostObj.inventory.other1 = 35 | # $hostObj.inventory.other2 = 36 | $hostObj.inventory.createdTime = $((get-date -format u).replace('Z','')); 37 | # $hostObj.inventory.deleteDate = '0000-00-00 00:00:00' 38 | $hostObj.inventory.sysman = $compSys.Vendor; #manufacturer 39 | $hostObj.inventory.sysproduct = $compSys.Name; #model 40 | $hostObj.inventory.sysversion = $compSys.Version; 41 | $hostObj.inventory.sysserial = $compSys.IdentifyingNumber; 42 | if ($compSys.UUID -notmatch "12345678-9012-3456-7890-abcdefabcdef" ) { 43 | $hostObj.inventory.sysuuid = $compSys.UUID; 44 | } else { 45 | $hostObj.inventory.sysuuid = ($compSys.Qualifiers | Where-Object Name -match 'UUID' | Select-Object -ExpandProperty Value); 46 | } 47 | $hostObj.inventory.systype = $case.chassistype; #device form factor found chassistype member of $case but it references a list that hasn't been updated anywhere I can find. i.e. returns 35 for a minipc but documented list only goes to 24 48 | $hostObj.inventory.biosversion = $bios.name; 49 | $hostObj.inventory.biosvendor = $bios.Manufacturer; 50 | $hostObj.inventory.biosdate = $(get-date $info.BiosReleaseDate -Format d); 51 | $hostObj.inventory.mbman = $baseBoard.Manufacturer; 52 | $hostObj.inventory.mbproductname = $baseBoard.Product; 53 | $hostObj.inventory.mbversion = $baseBoard.Version; 54 | $hostObj.inventory.mbserial = $baseBoard.SerialNumber; 55 | $hostObj.inventory.mbasset = $baseBoard.Tag; 56 | $hostObj.inventory.cpuman = $cpu.Manufacturer; 57 | $hostObj.inventory.cpuversion = $cpu.Name; 58 | $hostObj.inventory.cpucurrent = "Current Speed: $($cpu.currentClockSpeed) MHz"; 59 | $hostObj.inventory.cpumax = "Max Speed $($cpu.MaxClockSpeed) MHz"; 60 | $hostObj.inventory.mem = "MemTotal: $($comp.TotalPhysicalMemory) kB"; 61 | $hostObj.inventory.hdmodel = $hdd.Model; 62 | $hostObj.inventory.hdserial = $hdd.SerialNumber; 63 | $hostObj.inventory.hdfirmware = $hdd.FirmareRevision; 64 | $hostObj.inventory.caseman = $case.Manufacturer; 65 | $hostObj.inventory.casever = $case.Version; 66 | $hostObj.inventory.caseserial = $case.SerialNumber; 67 | $hostObj.inventory.caseasset = $case.SMBIOSAssetTag; 68 | $hostObj.inventory.memory = "$([MATH]::Round($(($comp.TotalPhysicalMemory) / 1GB),2)) GiB"; 69 | } 70 | 71 | end { 72 | $jsonData = $hostObj.inventory | ConvertTo-Json; 73 | return $jsonData; 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/Public/Get-FogLog.ps1: -------------------------------------------------------------------------------- 1 | function Get-FogLog { 2 | <# 3 | .SYNOPSIS 4 | Get a auto updating fog log 5 | 6 | .DESCRIPTION 7 | Ust get-content -wait to show a dynamic fog log or use -static to just see the current contents 8 | 9 | .PARAMETER static 10 | show the static contents of the fog log 11 | 12 | #> 13 | 14 | [CmdletBinding()] 15 | param ( 16 | [switch]$static 17 | ) 18 | 19 | begin { 20 | $fogLog = 'C:\fog.log'; 21 | } 22 | 23 | process { 24 | if (!$static) { 25 | "Starting dynamic fog log in new window, Hit Ctrl+C on new window or close it to exit dynamic fog log" | Out-Host; 26 | Start-Process Powershell.exe -ArgumentList "-Command `"Get-Content $fogLog -Wait`""; 27 | } 28 | else { 29 | Get-Content $fogLog; 30 | } 31 | } 32 | 33 | end { 34 | return; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/Public/Get-FogObject.ps1: -------------------------------------------------------------------------------- 1 | function Get-FogObject { 2 | <# 3 | .SYNOPSIS 4 | Gets a fog object via the api 5 | 6 | .DESCRIPTION 7 | Gets a object, objecactivetasktype, or performs a search via the api 8 | 9 | .PARAMETER type 10 | the type of object to get 11 | 12 | .PARAMETER jsonData 13 | the json data in json string format if required 14 | 15 | .PARAMETER IDofObject 16 | the id of the object to get 17 | 18 | #> 19 | 20 | [CmdletBinding()] 21 | param ( 22 | # The type of object being requested 23 | [Parameter(Position=0)] 24 | [ValidateSet("objectactivetasktype","object","search")] 25 | [string]$type, 26 | # The json data for the body of the request 27 | [Parameter(Position=2)] 28 | [Object]$jsonData, 29 | # The id of the object to get 30 | [Parameter(Position=3)] 31 | [string]$IDofObject 32 | ) 33 | 34 | DynamicParam { $paramDict = Set-DynamicParams $type; return $paramDict;} 35 | 36 | begin { 37 | $paramDict | % { New-Variable -Name $_.Keys -Value $($_.Values.Value);} 38 | Write-Verbose "Building uri and api call for $($paramDict.keys) $($paramDict.values.value)"; 39 | switch ($type) { 40 | objectactivetasktype { 41 | $uri = "$coreActiveTaskObject/current"; 42 | } 43 | object { 44 | if ($null -eq $IDofObject -OR $IDofObject -eq "") { 45 | $uri = "$coreObject"; 46 | } 47 | else { 48 | $uri = "$coreObject/$IDofObject"; 49 | } 50 | } 51 | search { 52 | $uri = "$type/$stringToSearch"; 53 | } 54 | } 55 | Write-Verbose "uri for get is $uri"; 56 | $apiInvoke = @{ 57 | uriPath=$uri; 58 | Method="GET"; 59 | jsonData=$jsonData; 60 | } 61 | if ($null -eq $apiInvoke.jsonData -OR $apiInvoke.jsonData -eq "") { 62 | $apiInvoke.Remove("jsonData"); 63 | } 64 | } 65 | 66 | process { 67 | $result = Invoke-FogApi @apiInvoke; 68 | } 69 | 70 | end { 71 | return $result; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/Public/Get-FogServerSettings.ps1: -------------------------------------------------------------------------------- 1 | function Get-FogServerSettings { 2 | <# 3 | .SYNOPSIS 4 | Gets the server settings set for this module 5 | 6 | .DESCRIPTION 7 | Gets the current settings for use in api calls 8 | 9 | #> 10 | 11 | [CmdletBinding()] 12 | param () 13 | 14 | begin { 15 | Write-Verbose "Pulling settings from settings file" 16 | $settingsFile = "$ENV:APPDATA\FogApi\api-settings.json" 17 | if (!(Test-path $settingsFile)) { 18 | if (!(Test-Path "$ENV:APPDATA\FogApi")) { 19 | mkdir "$ENV:APPDATA\FogApi"; 20 | } 21 | Copy-Item "$tools\settings.json" $settingsFile -Force 22 | } 23 | } 24 | 25 | process { 26 | $serverSettings = (Get-Content $settingsFile | ConvertFrom-Json); 27 | } 28 | 29 | end { 30 | return $serverSettings; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/Public/Get-FogSnapins.ps1: -------------------------------------------------------------------------------- 1 | function Get-FogSnapins { 2 | <# 3 | .SYNOPSIS 4 | Returns list of all snapins on fogserver 5 | 6 | .DESCRIPTION 7 | Gives a full list of all snapins on the fog server 8 | #> 9 | 10 | [CmdletBinding()] 11 | param () 12 | 13 | 14 | process { 15 | return (Invoke-FogApi -Method GET -uriPath snapin).snapins; 16 | } 17 | 18 | 19 | } -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/Public/Install-FogService.ps1: -------------------------------------------------------------------------------- 1 | function Install-FogService { 2 | <# 3 | .SYNOPSIS 4 | Attempts to install the fog service 5 | 6 | .DESCRIPTION 7 | Attempts to download and install silently and then not so silently the fog service 8 | 9 | .PARAMETER fogServer 10 | the server to download from and connect to 11 | 12 | #> 13 | 14 | [CmdletBinding()] 15 | param ( 16 | $fogServer = ((Get-FogServerSettings).fogServer) 17 | ) 18 | begin { 19 | $fileUrl = "http://$fogServer/fog/client/download.php?newclient"; 20 | $fileUrl2 = "http://$fogServer/fog/client/download.php?smartinstaller"; 21 | Write-Host "Making temp download dir"; 22 | mkdir C:\fogtemp; 23 | Write-Host "downloading installer"; 24 | Invoke-WebRequest -URI $fileUrl -UseBasicParsing -OutFile 'C:\fogtemp\fog.msi'; 25 | Invoke-WebRequest -URI $fileUrl2 -UseBasicParsing -OutFile 'C:\fogtemp\fog.exe'; 26 | } 27 | process { 28 | Write-Host "installing fog service"; 29 | Start-Process -FilePath msiexec -ArgumentList @('/i','C:\fogtemp\fog,msi','/quiet','/qn','/norestart') -NoNewWindow -Wait; 30 | if ($null -eq (Get-Service FogService -EA 0)) { 31 | & "C:\fogTemp\fog.exe"; 32 | Write-Host "Waiting 10 seconds then sending 10 enter keys" 33 | Start-Sleep 10 34 | $wshell = New-Object -ComObject wscript.shell; 35 | $wshell.AppActivate('Fog Service Setup') 36 | $wshell.SendKeys("{Enter}") 37 | $wshell.SendKeys("{Space}") 38 | $wshell.SendKeys("{Enter}") 39 | $wshell.SendKeys("{Enter}") 40 | $wshell.SendKeys("{Enter}") 41 | $wshell.SendKeys("{Enter}") 42 | Write-Host "waiting 30 seconds for service to install" 43 | Start-Sleep 30 44 | Write-host "sending more enter keys" 45 | $wshell.SendKeys("{Enter}") 46 | $wshell.SendKeys("{Enter}") 47 | $wshell.SendKeys("{Enter}") 48 | $wshell.SendKeys("{Enter}") 49 | $wshell.SendKeys("{Enter}") 50 | } 51 | } 52 | end { 53 | Write-Host "removing download file and temp folder"; 54 | Remove-Item -Force -Recurse C:\fogtemp; 55 | Write-Host "Starting fogservice"; 56 | if ($null -ne (Get-Service FogService)) { 57 | Start-Service FOGService; 58 | } 59 | return; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/Public/Invoke-FogApi.ps1: -------------------------------------------------------------------------------- 1 | function Invoke-FogApi { 2 | <# 3 | .SYNOPSIS 4 | a cmdlet function for making fogAPI calls via powershell 5 | 6 | .DESCRIPTION 7 | Takes a few parameters with some pulled from settings.json and others are put in from the wrapper cmdlets 8 | Makes a call to the api of a fog server and returns the results of the call 9 | The returned value is an object that can then be easily filtered, processed, 10 | and otherwise manipulated in poweshell. 11 | The defaults for each setting explain how to find or a description of the property needed. 12 | fogApiToken = "fog API token found at https://fog-server/fog/management/index.php?node=about&sub=settings under API System"; 13 | fogUserToken = "your fog user api token found in the user settings https://fog-server/fog/management/index.php?node=user&sub=list select your api enabled used and view the api tab"; 14 | fogServer = "your fog server hostname or ip address to be used for created the url used in api calls default is fog-server or fogServer"; 15 | 16 | .PARAMETER serverSettings 17 | this variable pulls the values from settings.json and assigns the values to 18 | the associated params. The defaults explain how to get the needed settings 19 | fogApiToken = "fog API token found at https://fog-server/fog/management/index.php?node=about&sub=settings under API System"; 20 | fogUserToken = "your fog user api token found in the user settings https://fog-server/fog/management/index.php?node=user&sub=list select your api enabled used and view the api tab"; 21 | fogServer = "your fog server hostname or ip address to be used for created the url used in api calls default is fog-server or fogServer"; 22 | 23 | .PARAMETER fogApiToken 24 | a string of your fogApiToken gotten from the fog web ui. 25 | this value is pulled from the settings.json file 26 | 27 | .PARAMETER fogUserToken 28 | a string of your fog user token gotten from the fog web ui in the user section. 29 | this value is pulled from the settings.json file 30 | 31 | .PARAMETER fogServer 32 | The hostname or ip address of your fogserver, 33 | defaults to the default name fog-server 34 | this value is pulled from the settings.json file 35 | 36 | .PARAMETER uriPath 37 | Put in the path of the apicall that would follow http://fog-server/fog/ 38 | i.e. 'host/1234' would access the host with an id of 1234 39 | This is filled by the wrapper commands using parameter validation to 40 | help ensure using the proper object names for the url 41 | 42 | .PARAMETER Method 43 | Defaults to 'Get' can also be Post, put, or delete, this param is handled better 44 | by the wrapper functions 45 | get is Get-fogObject 46 | post is New-fogObject 47 | delete is Remove-fogObject 48 | put is Update-fogObject 49 | 50 | .PARAMETER jsonData 51 | The jsondata string for including data in the body of a request 52 | 53 | .EXAMPLE 54 | #if you had the api tokens set as default values and wanted to get all hosts and info you could run this, assuming your fogserver is accessible on http://fog-server 55 | Invoke-FogApi; 56 | 57 | .Example 58 | #if your fogserver was named rawr and you wanted to put rename host 123 to meow 59 | Invoke-FogApi -fogServer "rawr" -uriPath "host/123" -Method "Put" -jsonData "{ `"name`": meow }"; 60 | 61 | .Link 62 | https://news.fogproject.org/simplified-api-documentation/ 63 | 64 | .NOTES 65 | The online version of this help takes you to the fog project api help page 66 | 67 | #> 68 | 69 | [CmdletBinding()] 70 | param ( 71 | [string]$uriPath, 72 | [string]$Method="GET", 73 | [string]$jsonData 74 | ) 75 | 76 | begin { 77 | Write-Verbose "Pulling settings from settings file" 78 | # Set-FogServerSettings; 79 | $serverSettings = Get-FogServerSettings; 80 | 81 | [string]$fogApiToken = $serverSettings.fogApiToken; 82 | [string]$fogUserToken = $serverSettings.fogUserToken; 83 | [string]$fogServer = $serverSettings.fogServer; 84 | 85 | $baseUri = "http://$fogServer/fog"; 86 | 87 | # Create headers 88 | Write-Verbose "Building Headers..."; 89 | $headers = @{}; 90 | $headers.Add('fog-api-token', $fogApiToken); 91 | $headers.Add('fog-user-token', $fogUserToken); 92 | 93 | # Set the Uri 94 | Write-Verbose "Building api call URI..."; 95 | $uri = "$baseUri/$uriPath"; 96 | $uri = $uri.Replace('//','/') 97 | $uri = $uri.Replace('http:/','http://') 98 | 99 | 100 | $apiCall = @{ 101 | Uri = $uri; 102 | Method = $Method; 103 | Headers = $headers; 104 | Body = $jsonData; 105 | ContentType = "application/json" 106 | } 107 | if ($null -eq $apiCall.Body -OR $apiCall.Body -eq "") { 108 | Write-Verbose "removing body from call as it is null" 109 | $apiCall.Remove("Body"); 110 | } 111 | 112 | } 113 | 114 | process { 115 | Write-Verbose "$Method`ing $jsonData to/from $uri"; 116 | try { 117 | $result = Invoke-RestMethod @apiCall -ea Stop; 118 | } catch { 119 | $result = Invoke-WebRequest @apiCall; 120 | } 121 | } 122 | 123 | end { 124 | Write-Verbose "finished api call"; 125 | return $result; 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/Public/New-FogObject.ps1: -------------------------------------------------------------------------------- 1 | function New-FogObject { 2 | <# 3 | .SYNOPSIS 4 | Create a new fog object with the api 5 | 6 | .DESCRIPTION 7 | creates a new object such as a host or task 8 | 9 | .PARAMETER type 10 | the type of api object 11 | 12 | .PARAMETER jsonData 13 | json data in json string for api call 14 | 15 | .PARAMETER IDofObject 16 | the id of the object 17 | 18 | #> 19 | 20 | [CmdletBinding()] 21 | param ( 22 | # The type of object being requested 23 | [Parameter(Position=0)] 24 | [ValidateSet("objecttasktype","object")] 25 | [string] 26 | $type, 27 | # The json data for the body of the request 28 | [Parameter(Position=2)] 29 | [Object]$jsonData, 30 | # The id of the object when creating a new task 31 | [Parameter(Position=3)] 32 | [string]$IDofObject 33 | ) 34 | 35 | DynamicParam { $paramDict = Set-DynamicParams $type; return $paramDict;} 36 | 37 | begin { 38 | $paramDict | % { New-Variable -Name $_.Keys -Value $($_.Values.Value);} 39 | Write-Verbose "Building uri and api call"; 40 | switch ($type) { 41 | objecttasktype { 42 | $uri = "$CoreTaskObject/$IDofObject/task"; 43 | } 44 | object { 45 | $uri = "$CoreObject/create"; 46 | } 47 | } 48 | $apiInvoke = @{ 49 | uriPath=$uri; 50 | Method="POST"; 51 | jsonData=$jsonData; 52 | } 53 | } 54 | 55 | process { 56 | $result = Invoke-FogApi @apiInvoke; 57 | } 58 | 59 | end { 60 | return $result; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/Public/Remove-FogObject.ps1: -------------------------------------------------------------------------------- 1 | function Remove-FogObject { 2 | <# 3 | .SYNOPSIS 4 | Removes/Deletes a object via fog api 5 | 6 | .DESCRIPTION 7 | Calls a delete function via the api 8 | 9 | .PARAMETER type 10 | the type of api object 11 | 12 | .PARAMETER jsonData 13 | json data in json string 14 | 15 | .PARAMETER IDofObject 16 | the id of the object 17 | 18 | #> 19 | 20 | [CmdletBinding()] 21 | param ( 22 | # The type of object being requested 23 | [Parameter(Position=0)] 24 | [ValidateSet("objecttasktype","objectactivetasktype","object")] 25 | [string]$type, 26 | # The json data for the body of the request 27 | [Parameter(Position=2)] 28 | [Object]$jsonData, 29 | # The id of the object to remove 30 | [Parameter(Position=3)] 31 | [string]$IDofObject 32 | ) 33 | 34 | DynamicParam { $paramDict = Set-DynamicParams $type; return $paramDict;} 35 | 36 | begin { 37 | $paramDict | ForEach-Object { New-Variable -Name $_.Keys -Value $($_.Values.Value);} 38 | Write-Verbose "Building uri and api call"; 39 | switch ($type) { 40 | objecttasktype { 41 | $uri = "$CoreTaskObject/$IDofObject/cancel"; 42 | } 43 | object { 44 | $uri = "$CoreObject/$IDofObject/delete"; 45 | } 46 | objectactivetasktype { 47 | $uri = "$CoreActiveTaskObject/cancel" 48 | } 49 | } 50 | $apiInvoke = @{ 51 | uriPath=$uri; 52 | Method="DELETE"; 53 | jsonData=$jsonData; 54 | } 55 | if ($apiInvoke.jsonData -eq $null -OR $apiInvoke.jsonData -eq "") { 56 | $apiInvoke.Remove("jsonData"); 57 | } 58 | } 59 | 60 | process { 61 | $result = Invoke-FogApi @apiInvoke; 62 | } 63 | 64 | end { 65 | return $result; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/Public/Set-FogInventory.ps1: -------------------------------------------------------------------------------- 1 | function Set-FogInventory { 2 | <# 3 | .SYNOPSIS 4 | Sets a fog hosts inventory 5 | 6 | .DESCRIPTION 7 | Sets the inventory of a fog host object to json data gotten from get-foginventory 8 | 9 | .PARAMETER hostObj 10 | the host object to set on 11 | 12 | .PARAMETER jsonData 13 | the jsondata with the inventory 14 | 15 | #> 16 | 17 | [CmdletBinding()] 18 | param ( 19 | $hostObj = (Get-FogHost), 20 | $jsonData = (Get-FogInventory -hostObj $hostObj) 21 | ) 22 | 23 | begin { 24 | $inventoryApi = @{ 25 | jsonData = $jsonData; 26 | Method = 'Post'; 27 | uriPath = "inventory/new"; 28 | } 29 | } 30 | 31 | process { 32 | Invoke-FogApi @inventoryApi -verbose; 33 | } 34 | 35 | end { 36 | return; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/Public/Set-FogServerSettings.ps1: -------------------------------------------------------------------------------- 1 | function Set-FogServerSettings { 2 | <# 3 | .SYNOPSIS 4 | Set fog server settings 5 | 6 | .DESCRIPTION 7 | Set the apitokens and server settings for api calls with this module 8 | the settings are stored in a json file in the current users roaming appdata ($ENV:APPDATA\FogApi) 9 | this is to keep it locked down and inaccessible to standard users 10 | and keeps the settings from being overwritten when updating the module 11 | 12 | .PARAMETER fogApiToken 13 | fog API token found at https://fog-server/fog/management/index.php?node=about&sub=settings under API System 14 | 15 | .PARAMETER fogUserToken 16 | your fog user api token found in the user settings https://fog-server/fog/management/index.php?node=user&sub=list select your api enabled used and view the api tab 17 | 18 | .PARAMETER fogServer 19 | your fog server hostname or ip address to be used for created the url used in api calls default is fog-server or fogServer 20 | 21 | .PARAMETER interactive 22 | switch to make setting these an interactive process 23 | 24 | #> 25 | 26 | [CmdletBinding()] 27 | param ( 28 | [string]$fogApiToken, 29 | [string]$fogUserToken, 30 | [string]$fogServer, 31 | [switch]$interactive 32 | ) 33 | begin { 34 | 35 | $settingsFile = "$ENV:APPDATA\FogApi\api-settings.json" 36 | if (!(Test-path $settingsFile)) { 37 | if (!(Test-Path "$ENV:APPDATA\FogApi")) { 38 | mkdir "$ENV:APPDATA\FogApi"; 39 | } 40 | Copy-Item "$tools\settings.json" $settingsFile -Force 41 | } 42 | $ServerSettings = Get-FogServerSettings; 43 | Write-Verbose "Current/old Settings are $($ServerSettings)"; 44 | $helpTxt = @{ 45 | fogApiToken = "fog API token found at https://fog-server/fog/management/index.php?node=about&sub=settings under API System"; 46 | fogUserToken = "your fog user api token found in the user settings https://fog-server/fog/management/index.php?node=user&sub=list select your api enabled used and view the api tab"; 47 | fogServer = "your fog server hostname or ip address to be used for created the url used in api calls default is fog-server or fogServer"; 48 | } 49 | 50 | } 51 | 52 | process { 53 | if($null -ne $fogApiToken -and $null -ne $fogUserToken -AND $null -ne $fogServer) { 54 | $serverSettings = @{ 55 | fogApiToken = $fogApiToken; 56 | fogUserToken = $fogUserToken; 57 | fogServer = $fogServer; 58 | } 59 | } 60 | # If given paras are null just pulls from settings file 61 | # If they are not null sets the object to passed value 62 | if($interactive) { 63 | $serverSettings.psobject.properties | ForEach-Object { 64 | $var = (Get-Variable -Name $_.Name); 65 | if ($null -eq $var.Value -OR $var.Value -eq "") { 66 | Set-Variable -name $var.Name -Value (Read-Host -Prompt "Enter the $($var.name), help message: $($helpTxt.($_.name)) "); 67 | } 68 | } 69 | } 70 | 71 | 72 | Write-Verbose "making sure all settings are set"; 73 | if ( $ServerSettings.fogApiToken -eq $helpTxt.fogApiToken -OR 74 | $ServerSettings.fogUserToken -eq $helpTxt.fogUserToken -OR $ServerSettings.fogServer -eq $helpTxt.fogServer) { 75 | Write-Host -BackgroundColor Yellow -ForegroundColor Red -Object "a fog setting is still set to its default help text, opening the settings file for you to set the settings" 76 | Write-Host -BackgroundColor Yellow -ForegroundColor Red -Object "This script will close after opening settings in notepad, please re-run command after updating settings file"; 77 | if ($isLinux) { 78 | $editor = 'nano'; 79 | } 80 | elseif($IsMacOS) { 81 | $editor = 'TextEdit'; 82 | } 83 | else { 84 | $editor = 'notepad.exe'; 85 | } 86 | Start-Process -FilePath $editor -ArgumentList "$SettingsFile" -NoNewWindow -PassThru; 87 | return; 88 | } 89 | } 90 | 91 | end { 92 | Write-Verbose "Writing new Settings"; 93 | $serverSettings | ConvertTo-Json | Out-File -FilePath $settingsFile -Encoding oem -Force; 94 | return (Get-Content $settingsFile | ConvertFrom-Json); 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/Public/Set-FogSnapins.ps1: -------------------------------------------------------------------------------- 1 | function Set-FogSnapins { 2 | <# 3 | .SYNOPSIS 4 | Sets a list of snapins to a host, appends to existing ones 5 | 6 | .DESCRIPTION 7 | Goes through a provided list variable and adds each matching snapin to the provided 8 | hostid 9 | 10 | .EXAMPLE 11 | Set-FogSnapins -hostid (Get-FogHost).id -pkgList @('Office365','chrome','slack') 12 | 13 | This would associate snapins that match the titles of office365, chrome, and slack to the provided host id 14 | they could then be deployed with start-fogsnapins 15 | 16 | .NOTES 17 | General notes 18 | #> 19 | 20 | [CmdletBinding()] 21 | [Alias('Add-FogSnapins')] 22 | param ( 23 | $hostid = ((Get-FogHost).id), 24 | $pkgList, 25 | $dept 26 | ) 27 | 28 | process { 29 | Write-Verbose "Association snapins from package list with host"; 30 | $snapins = Get-FogSnapins; 31 | $urlPath = "snapinassociation/create" 32 | $curSnapins = Get-FogAssociatedSnapins -hostId $hostid; 33 | $result = New-Object System.Collections.Generic.List[Object]; 34 | $pkgList | ForEach-Object { 35 | $json = @{ 36 | hostID = $hostid 37 | snapinID = (($snapins | Where-Object name -match "$($_)").id); 38 | }; 39 | Write-Verbose "$_ is pkg snapin id found is $($json.snapinID)"; 40 | if (($null -ne $json.SnapinID) -AND ($json.SnapinID -notin $curSnapins.id)) { 41 | $json = $json | ConvertTo-Json; 42 | $result.add((New-FogObject -type object -coreObject snapinassociation -jsonData $json)); 43 | } elseif ($json.SnapinID -in $curSnapins.id) { 44 | Write-Warning "$_ snapin of id $($json.SnapinID) is already associated with this host"; 45 | } else { 46 | Write-Warning "no snapin ID found for $_ pkg"; 47 | } 48 | # Invoke-FogApi -Method POST -uriPath $urlPath -jsonData $json; 49 | } 50 | return $result; 51 | } 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/Public/Start-FogSnapins.ps1: -------------------------------------------------------------------------------- 1 | function Start-FogSnapins { 2 | <# 3 | .SYNOPSIS 4 | Starts all associated snapins of a host 5 | 6 | .DESCRIPTION 7 | Starts the allsnapins task on a provided hostid 8 | 9 | .PARAMETER hostid 10 | the hostid to start the task on 11 | 12 | .PARAMETER taskTypeid 13 | the id of the task to start, defaults to 12 14 | 15 | .EXAMPLE 16 | Start-FogSnapins 17 | 18 | will get the current hosts id and start all snapins on it 19 | #> 20 | 21 | [CmdletBinding()] 22 | param ( 23 | $hostid = ((Get-FogHost).id), 24 | $taskTypeid = 12 25 | ) 26 | 27 | begin { 28 | Write-Verbose "Stopping any queued snapin tasks"; 29 | try { 30 | $tasks = Get-FogObject -type objectactivetasktype -coreActiveTaskObject task; 31 | } catch { 32 | $tasks = Invoke-FogApi -Method GET -uriPath "task/active"; 33 | } 34 | $taskID = (($tasks | Where-Object hostID -match $hostid).id); 35 | Write-Verbose "Found $($taskID.count) tasks deleting them now"; 36 | $taskID | ForEach-Object{ 37 | try { 38 | Remove-FogObject -type objecttasktype -coreTaskObject task -IDofObject $_; 39 | } catch { 40 | Invoke-FogApi -Method DELETE -uriPath "task/$_/cancel"; 41 | } 42 | } 43 | # $snapAssocs = Invoke-FogApi -uriPath snapinassociation -Method Get; 44 | # $snaps = $snapAssocs.snapinassociations | ? hostid -eq $hostid; 45 | } 46 | 47 | process { 48 | Write-Verbose "starting all snapin task for host"; 49 | $json = (@{ 50 | "taskTypeID"=$taskTypeid; 51 | "deploySnapins"=-1; 52 | } | ConvertTo-Json); 53 | New-FogObject -type objecttasktype -coreTaskObject host -jsonData $json -IDofObject $hostid; 54 | } 55 | 56 | end { 57 | Write-Verbose "Snapin tasks have been queued on the server"; 58 | return; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/Public/Update-FogObject.ps1: -------------------------------------------------------------------------------- 1 | function Update-FogObject { 2 | <# 3 | .SYNOPSIS 4 | Update/patch/edit api calls 5 | 6 | .DESCRIPTION 7 | Runs update calls to the api 8 | 9 | .PARAMETER type 10 | the type of fog object 11 | 12 | .PARAMETER jsonData 13 | the json data string 14 | 15 | .PARAMETER IDofObject 16 | The ID of the object 17 | 18 | .PARAMETER uri 19 | The explicit uri to use 20 | 21 | .NOTES 22 | just saw this and just today was finding some issue with Update-fogobject 23 | The issue appears to be with the dynamic parameter variable I have in the function for the coreobjecttype. 24 | For some reason it is working when you call the function and brings up all the coreobject type choices but then the variable is being set to null when the function is running. 25 | Meaning that when function builds the uri it only gets 26 | http://fogserver/fog//id/edit 27 | instead of 28 | http://fogserver/fog/coreObjectType/id/edit 29 | 30 | So one workaround I will try to publish by the end of the day is adding an optional uri parameter to that function so that you can manually override it when neccesarry. 31 | Also I should really add more documentation to each of the functions instead of just having it all under Invoke-fogapi 32 | 33 | I also will add a try/catch block to invoke-fogapi for when invoke-restmethod fails and have it try invoke-webrequest. 34 | #> 35 | [CmdletBinding()] 36 | [Alias('Set-FogObject')] 37 | param ( 38 | # The type of object being requested 39 | [Parameter(Position=0)] 40 | [ValidateSet("object")] 41 | [string]$type, 42 | # The json data for the body of the request 43 | [Parameter(Position=2)] 44 | [Object]$jsonData, 45 | # The id of the object to remove 46 | [Parameter(Position=3)] 47 | [string]$IDofObject, 48 | [Parameter(Position=4)] 49 | [string]$uri 50 | ) 51 | 52 | DynamicParam { $paramDict = Set-DynamicParams $type; return $paramDict; } 53 | 54 | begin { 55 | $paramDict | ForEach-Object { New-Variable -Name $_.Keys -Value $($_.Values.Value);} 56 | Write-Verbose "Building uri and api call"; 57 | if([string]::IsNullOrEmpty($uri)) { 58 | $uri = "$CoreObject/$IDofObject/edit"; 59 | } 60 | 61 | $apiInvoke = @{ 62 | uriPath=$uri; 63 | Method="PUT"; 64 | jsonData=$jsonData; 65 | } 66 | } 67 | 68 | process { 69 | $result = Invoke-FogApi @apiInvoke; 70 | } 71 | 72 | end { 73 | return $result; 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/Readme.md: -------------------------------------------------------------------------------- 1 | To install this module you need at least powershell v3, was created with 5.1 and intended to be cross platform compatible with powershell v6 2 | To Install this module follow these steps 3 | * Easiest method: Install from PSGallery https://www.powershellgallery.com/packages/FogApi `Install-Module -name fogApi` 4 | 5 | * Manual Method: 6 | * download the zip of this repo https://github.com/FOGProject/fog-community-scripts/archive/master.zip and extract it 7 | * Or clone the repo using your favorite git tool, you just need the FogApi Folder this readme is in 8 | * Copy the FogApi folder this Readme file is in to... 9 | * For Windows Powershell v3-v5.1 10 | * C:\Program Files\WindowsPowershell\Modules 11 | * For Windows Powershell v6+ 12 | * C:\Program Files\PowerShell\6-preview\Modules 13 | * 6-Preview may need to be replaced with whatever current version you have installed 14 | * For Linux Powershell v6+ 15 | * /opt/microsoft/powershell/6.1.0-preview.2/Modules 16 | * 6.1.0-preview.2 may need to be replaced with whatever current version you have installed 17 | * For Mac Powershell v6+ (untested) 18 | * /usr/local/microsoft/powershell/6.x/Modules 19 | * 6.x should be replaced with whatever most current version you are using 20 | * I haven't tested this on a mac, the module folder may be somewhere else 21 | this is based on where it is in other powershell 6 installs 22 | * Open a powershell command prompt (I always run as admin, unsure if it's required) 23 | * Run `Import-Module FogApi` 24 | 25 | The module is now installed. 26 | The first time you try to run a command the settings.json file will automatically open 27 | in notepad on windows, nano on linux, or TextEdit on Mac 28 | You can also open the settings.json file and edit it manually before running your first command. 29 | The default settings are explanations of where to find the proper settings since json can't have comments 30 | 31 | Once the settings are set you can have a jolly good time utilzing the fog documentation 32 | found here https://news.fogproject.org/simplified-api-documentation/ that was used to model the parameters 33 | 34 | i.e. 35 | 36 | Get-FogObject has a type param that validates to object, objectactivetasktype, and search as those are the options given in the documentation. 37 | Each of those types validates (which means autocompletion) to the core types listed in the documentation. 38 | So if you typed in `Get-FogObject -Type object -Object h` and then started hitting tab, it would loop through the possible core objects you can get from the api that start with 'h' such as history, host, etc. 39 | 40 | Unless you filter a get with a json body it will return all the results into a powershell object. That object is easy to work with to create other commands. Note: Full Pipeline support will come at a later time 41 | i.e. 42 | 43 | `$hosts = Get-FogObject -Type Object -CoreObject Host `# calls get on http://fog-server/fog/host to list all hosts 44 | Now you can search all your hosts for the one or ones you're looking for with powershell 45 | maybe you want to find all the hosts with 'IT' in the name (note '?' is an alias for Where-Object) 46 | `$ITHosts = $hosts.hosts | ? name -match 'IT';` 47 | 48 | Now maybe you want to change the image all of these computers use to one named 'IT-Image' 49 | You can edit the object in powershell with a foreach-object ('%' is an alias for foreach-object) 50 | `$updatedITHosts = $ITHosts | % { $_.imagename = 'IT-image'}` 51 | 52 | Then you need to convert that object to json and pass each object into one api call at a time. Which sounds complicated, but it's not, it's as easy as 53 | ``` 54 | $updateITHosts | % { 55 | $jsonData = $_ | ConvertTo-Json; 56 | Update-FogObject -Type object -CoreObject host -objectID $_.id -jsonData $jsonData; 57 | #successful result of updated objects properties 58 | #or any error messages will output to screen for each object 59 | } 60 | ``` 61 | 62 | This is just one small example of the limitless things you can do with the api and powershell objects. 63 | 64 | see also the fogforum thread for the module https://forums.fogproject.org/topic/12026/powershell-api-module/2 65 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/Tools/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "fogApiToken": "fog API token found at https://fog-server/fog/management/index.php?node=about&sub=settings under API System", 3 | "fogUserToken": "your fog user api token found in the user settings https://fog-server/fog/management/index.php?node=user&sub=list select your api enabled used and view the api tab", 4 | "fogServer": "your fog server hostname or ip address to be used for created the url used in api calls default is fog-server or fogServer" 5 | } 6 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/docs/Get-FogAssociatedSnapins.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: fogapi-help.xml 3 | Module Name: fogapi 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-FogAssociatedSnapins 9 | 10 | ## SYNOPSIS 11 | Returns list of all snapins associated with a hostid 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Get-FogAssociatedSnapins [[-hostId] ] [] 17 | ``` 18 | 19 | ## DESCRIPTION 20 | Gives a full list of all snapins associated with a given host 21 | 22 | ## EXAMPLES 23 | 24 | ### Example 1 25 | ```powershell 26 | PS C:\> {{ Add example code here }} 27 | ``` 28 | 29 | {{ Add example description here }} 30 | 31 | ## PARAMETERS 32 | 33 | ### -hostId 34 | {{ Fill hostId Description }} 35 | 36 | ```yaml 37 | Type: Object 38 | Parameter Sets: (All) 39 | Aliases: 40 | 41 | Required: False 42 | Position: 1 43 | Default value: ((Get-FogHost).id) 44 | Accept pipeline input: False 45 | Accept wildcard characters: False 46 | ``` 47 | 48 | ### CommonParameters 49 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 50 | 51 | ## INPUTS 52 | 53 | ## OUTPUTS 54 | 55 | ## NOTES 56 | 57 | ## RELATED LINKS 58 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/docs/Get-FogGroup.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: fogapi-help.xml 3 | Module Name: fogapi 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-FogGroup 9 | 10 | ## SYNOPSIS 11 | needs to return the group name of the group that isn't the everyone group 12 | will use groupassociation call to get group id then group id to get group name from group uriPath 13 | 14 | ## SYNTAX 15 | 16 | ``` 17 | Get-FogGroup [[-hostId] ] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | requires the id of the host you want the groups that aren't the everyone group for 22 | 23 | ## EXAMPLES 24 | 25 | ### Example 1 26 | ```powershell 27 | PS C:\> {{ Add example code here }} 28 | ``` 29 | 30 | {{ Add example description here }} 31 | 32 | ## PARAMETERS 33 | 34 | ### -hostId 35 | {{ Fill hostId Description }} 36 | 37 | ```yaml 38 | Type: Int32 39 | Parameter Sets: (All) 40 | Aliases: 41 | 42 | Required: False 43 | Position: 1 44 | Default value: 0 45 | Accept pipeline input: False 46 | Accept wildcard characters: False 47 | ``` 48 | 49 | ### CommonParameters 50 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 51 | 52 | ## INPUTS 53 | 54 | ## OUTPUTS 55 | 56 | ## NOTES 57 | 58 | ## RELATED LINKS 59 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/docs/Get-FogHost.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: fogapi-help.xml 3 | Module Name: fogapi 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-FogHost 9 | 10 | ## SYNOPSIS 11 | Gets the object of a specific fog host 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Get-FogHost [[-uuid] ] [[-hostName] ] [[-macAddr] ] [[-hosts] ] 17 | [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | Searches a new or existing object of hosts for a specific host (or hosts) with search options of uuid, hostname, or mac address 22 | if no search terms are specified then it gets the search terms from your host that is making the request and tries to find your 23 | computer in fog 24 | 25 | ## EXAMPLES 26 | 27 | ### EXAMPLE 1 28 | ``` 29 | Get-FogHost -hostName MewoMachine 30 | ``` 31 | 32 | This would return the fog details of a host named MeowMachine in your fog instance 33 | 34 | ### EXAMPLE 2 35 | ``` 36 | Get-FogHost 37 | ``` 38 | 39 | If you specify no param it will return your current host from fog 40 | 41 | ## PARAMETERS 42 | 43 | ### -uuid 44 | the uuid of the host 45 | 46 | ```yaml 47 | Type: String 48 | Parameter Sets: (All) 49 | Aliases: 50 | 51 | Required: False 52 | Position: 1 53 | Default value: None 54 | Accept pipeline input: False 55 | Accept wildcard characters: False 56 | ``` 57 | 58 | ### -hostName 59 | the hostname of the host 60 | 61 | ```yaml 62 | Type: String 63 | Parameter Sets: (All) 64 | Aliases: 65 | 66 | Required: False 67 | Position: 2 68 | Default value: None 69 | Accept pipeline input: False 70 | Accept wildcard characters: False 71 | ``` 72 | 73 | ### -macAddr 74 | a mac address linked to the host 75 | 76 | ```yaml 77 | Type: String 78 | Parameter Sets: (All) 79 | Aliases: 80 | 81 | Required: False 82 | Position: 3 83 | Default value: None 84 | Accept pipeline input: False 85 | Accept wildcard characters: False 86 | ``` 87 | 88 | ### -hosts 89 | defaults to calling Get-FogHosts but if you already have that in an object you can pass it here to speed up processing 90 | 91 | ```yaml 92 | Type: Object 93 | Parameter Sets: (All) 94 | Aliases: 95 | 96 | Required: False 97 | Position: 4 98 | Default value: (Get-FogHosts) 99 | Accept pipeline input: False 100 | Accept wildcard characters: False 101 | ``` 102 | 103 | ### CommonParameters 104 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 105 | 106 | ## INPUTS 107 | 108 | ## OUTPUTS 109 | 110 | ## NOTES 111 | 112 | ## RELATED LINKS 113 | 114 | [Get-FogHosts]() 115 | 116 | [Get-FogObject]() 117 | 118 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/docs/Get-FogHosts.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: fogapi-help.xml 3 | Module Name: fogapi 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-FogHosts 9 | 10 | ## SYNOPSIS 11 | Gets all fog hosts 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Get-FogHosts [] 17 | ``` 18 | 19 | ## DESCRIPTION 20 | helper function for get-fogobject that gets all host objects 21 | 22 | ## EXAMPLES 23 | 24 | ### EXAMPLE 1 25 | ``` 26 | Get-FogHosts 27 | ``` 28 | 29 | ## PARAMETERS 30 | 31 | ### CommonParameters 32 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 33 | 34 | ## INPUTS 35 | 36 | ## OUTPUTS 37 | 38 | ## NOTES 39 | 40 | ## RELATED LINKS 41 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/docs/Get-FogInventory.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: fogapi-help.xml 3 | Module Name: fogapi 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-FogInventory 9 | 10 | ## SYNOPSIS 11 | Gets a local computer's inventory with wmi and returns 12 | a json object that can be used to set fog inventory 13 | 14 | ## SYNTAX 15 | 16 | ``` 17 | Get-FogInventory [[-hostObj] ] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | Uses various wmi classes to get every possible inventory item to set in fog 22 | 23 | ## EXAMPLES 24 | 25 | ### Example 1 26 | ```powershell 27 | PS C:\> {{ Add example code here }} 28 | ``` 29 | 30 | {{ Add example description here }} 31 | 32 | ## PARAMETERS 33 | 34 | ### -hostObj 35 | the host to get the model of the inventory object from 36 | 37 | ```yaml 38 | Type: Object 39 | Parameter Sets: (All) 40 | Aliases: 41 | 42 | Required: False 43 | Position: 1 44 | Default value: (Get-FogHost) 45 | Accept pipeline input: False 46 | Accept wildcard characters: False 47 | ``` 48 | 49 | ### CommonParameters 50 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 51 | 52 | ## INPUTS 53 | 54 | ## OUTPUTS 55 | 56 | ## NOTES 57 | 58 | ## RELATED LINKS 59 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/docs/Get-FogLog.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: fogapi-help.xml 3 | Module Name: fogapi 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-FogLog 9 | 10 | ## SYNOPSIS 11 | Get a auto updating fog log 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Get-FogLog [-static] [] 17 | ``` 18 | 19 | ## DESCRIPTION 20 | Ust get-content -wait to show a dynamic fog log or use -static to just see the current contents 21 | 22 | ## EXAMPLES 23 | 24 | ### Example 1 25 | ```powershell 26 | PS C:\> {{ Add example code here }} 27 | ``` 28 | 29 | {{ Add example description here }} 30 | 31 | ## PARAMETERS 32 | 33 | ### -static 34 | show the static contents of the fog log 35 | 36 | ```yaml 37 | Type: SwitchParameter 38 | Parameter Sets: (All) 39 | Aliases: 40 | 41 | Required: False 42 | Position: Named 43 | Default value: False 44 | Accept pipeline input: False 45 | Accept wildcard characters: False 46 | ``` 47 | 48 | ### CommonParameters 49 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 50 | 51 | ## INPUTS 52 | 53 | ## OUTPUTS 54 | 55 | ## NOTES 56 | 57 | ## RELATED LINKS 58 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/docs/Get-FogObject.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: fogapi-help.xml 3 | Module Name: fogapi 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-FogObject 9 | 10 | ## SYNOPSIS 11 | Gets a fog object via the api 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Get-FogObject [[-type] ] [[-jsonData] ] [[-IDofObject] ] [] 17 | ``` 18 | 19 | ## DESCRIPTION 20 | Gets a object, objecactivetasktype, or performs a search via the api 21 | 22 | ## EXAMPLES 23 | 24 | ### Example 1 25 | ```powershell 26 | PS C:\> {{ Add example code here }} 27 | ``` 28 | 29 | {{ Add example description here }} 30 | 31 | ## PARAMETERS 32 | 33 | ### -type 34 | the type of object to get 35 | 36 | ```yaml 37 | Type: String 38 | Parameter Sets: (All) 39 | Aliases: 40 | 41 | Required: False 42 | Position: 1 43 | Default value: None 44 | Accept pipeline input: False 45 | Accept wildcard characters: False 46 | ``` 47 | 48 | ### -jsonData 49 | the json data in json string format if required 50 | 51 | ```yaml 52 | Type: Object 53 | Parameter Sets: (All) 54 | Aliases: 55 | 56 | Required: False 57 | Position: 3 58 | Default value: None 59 | Accept pipeline input: False 60 | Accept wildcard characters: False 61 | ``` 62 | 63 | ### -IDofObject 64 | the id of the object to get 65 | 66 | ```yaml 67 | Type: String 68 | Parameter Sets: (All) 69 | Aliases: 70 | 71 | Required: False 72 | Position: 4 73 | Default value: None 74 | Accept pipeline input: False 75 | Accept wildcard characters: False 76 | ``` 77 | 78 | ### CommonParameters 79 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 80 | 81 | ## INPUTS 82 | 83 | ## OUTPUTS 84 | 85 | ## NOTES 86 | 87 | ## RELATED LINKS 88 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/docs/Get-FogServerSettings.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: fogapi-help.xml 3 | Module Name: fogapi 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-FogServerSettings 9 | 10 | ## SYNOPSIS 11 | Gets the server settings set for this module 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Get-FogServerSettings [] 17 | ``` 18 | 19 | ## DESCRIPTION 20 | Gets the current settings for use in api calls 21 | 22 | ## EXAMPLES 23 | 24 | ### Example 1 25 | ```powershell 26 | PS C:\> {{ Add example code here }} 27 | ``` 28 | 29 | {{ Add example description here }} 30 | 31 | ## PARAMETERS 32 | 33 | ### CommonParameters 34 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 35 | 36 | ## INPUTS 37 | 38 | ## OUTPUTS 39 | 40 | ## NOTES 41 | 42 | ## RELATED LINKS 43 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/docs/Get-FogSnapins.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: fogapi-help.xml 3 | Module Name: fogapi 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-FogSnapins 9 | 10 | ## SYNOPSIS 11 | Returns list of all snapins on fogserver 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Get-FogSnapins [] 17 | ``` 18 | 19 | ## DESCRIPTION 20 | Gives a full list of all snapins on the fog server 21 | 22 | ## EXAMPLES 23 | 24 | ### Example 1 25 | ```powershell 26 | PS C:\> {{ Add example code here }} 27 | ``` 28 | 29 | {{ Add example description here }} 30 | 31 | ## PARAMETERS 32 | 33 | ### CommonParameters 34 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 35 | 36 | ## INPUTS 37 | 38 | ## OUTPUTS 39 | 40 | ## NOTES 41 | 42 | ## RELATED LINKS 43 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/docs/Install-FogService.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: fogapi-help.xml 3 | Module Name: fogapi 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Install-FogService 9 | 10 | ## SYNOPSIS 11 | Attempts to install the fog service 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Install-FogService [[-fogServer] ] [] 17 | ``` 18 | 19 | ## DESCRIPTION 20 | Attempts to download and install silently and then not so silently the fog service 21 | 22 | ## EXAMPLES 23 | 24 | ### Example 1 25 | ```powershell 26 | PS C:\> {{ Add example code here }} 27 | ``` 28 | 29 | {{ Add example description here }} 30 | 31 | ## PARAMETERS 32 | 33 | ### -fogServer 34 | the server to download from and connect to 35 | 36 | ```yaml 37 | Type: Object 38 | Parameter Sets: (All) 39 | Aliases: 40 | 41 | Required: False 42 | Position: 1 43 | Default value: ((Get-FogServerSettings).fogServer) 44 | Accept pipeline input: False 45 | Accept wildcard characters: False 46 | ``` 47 | 48 | ### CommonParameters 49 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 50 | 51 | ## INPUTS 52 | 53 | ## OUTPUTS 54 | 55 | ## NOTES 56 | 57 | ## RELATED LINKS 58 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/docs/Invoke-FogApi.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: fogapi-help.xml 3 | Module Name: fogapi 4 | online version: https://news.fogproject.org/simplified-api-documentation/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # Invoke-FogApi 9 | 10 | ## SYNOPSIS 11 | a cmdlet function for making fogAPI calls via powershell 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Invoke-FogApi [[-uriPath] ] [[-Method] ] [[-jsonData] ] [] 17 | ``` 18 | 19 | ## DESCRIPTION 20 | Takes a few parameters with some pulled from settings.json and others are put in from the wrapper cmdlets 21 | Makes a call to the api of a fog server and returns the results of the call 22 | The returned value is an object that can then be easily filtered, processed, 23 | and otherwise manipulated in poweshell. 24 | The defaults for each setting explain how to find or a description of the property needed. 25 | fogApiToken = "fog API token found at https://fog-server/fog/management/index.php?node=about&sub=settings under API System"; 26 | fogUserToken = "your fog user api token found in the user settings https://fog-server/fog/management/index.php?node=user&sub=list select your api enabled used and view the api tab"; 27 | fogServer = "your fog server hostname or ip address to be used for created the url used in api calls default is fog-server or fogServer"; 28 | 29 | ## EXAMPLES 30 | 31 | ### EXAMPLE 1 32 | ``` 33 | #if you had the api tokens set as default values and wanted to get all hosts and info you could run this, assuming your fogserver is accessible on http://fog-server 34 | ``` 35 | 36 | Invoke-FogApi; 37 | 38 | ### EXAMPLE 2 39 | ``` 40 | #if your fogserver was named rawr and you wanted to put rename host 123 to meow 41 | ``` 42 | 43 | Invoke-FogApi -fogServer "rawr" -uriPath "host/123" -Method "Put" -jsonData "{ \`"name\`": meow }"; 44 | 45 | ## PARAMETERS 46 | 47 | ### -uriPath 48 | Put in the path of the apicall that would follow http://fog-server/fog/ 49 | i.e. 50 | 'host/1234' would access the host with an id of 1234 51 | This is filled by the wrapper commands using parameter validation to 52 | help ensure using the proper object names for the url 53 | 54 | ```yaml 55 | Type: String 56 | Parameter Sets: (All) 57 | Aliases: 58 | 59 | Required: False 60 | Position: 1 61 | Default value: None 62 | Accept pipeline input: False 63 | Accept wildcard characters: False 64 | ``` 65 | 66 | ### -Method 67 | Defaults to 'Get' can also be Post, put, or delete, this param is handled better 68 | by the wrapper functions 69 | get is Get-fogObject 70 | post is New-fogObject 71 | delete is Remove-fogObject 72 | put is Update-fogObject 73 | 74 | ```yaml 75 | Type: String 76 | Parameter Sets: (All) 77 | Aliases: 78 | 79 | Required: False 80 | Position: 2 81 | Default value: GET 82 | Accept pipeline input: False 83 | Accept wildcard characters: False 84 | ``` 85 | 86 | ### -jsonData 87 | The jsondata string for including data in the body of a request 88 | 89 | ```yaml 90 | Type: String 91 | Parameter Sets: (All) 92 | Aliases: 93 | 94 | Required: False 95 | Position: 3 96 | Default value: None 97 | Accept pipeline input: False 98 | Accept wildcard characters: False 99 | ``` 100 | 101 | ### CommonParameters 102 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 103 | 104 | ## INPUTS 105 | 106 | ## OUTPUTS 107 | 108 | ## NOTES 109 | The online version of this help takes you to the fog project api help page 110 | 111 | ## RELATED LINKS 112 | 113 | [https://news.fogproject.org/simplified-api-documentation/](https://news.fogproject.org/simplified-api-documentation/) 114 | 115 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/docs/New-FogObject.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: fogapi-help.xml 3 | Module Name: fogapi 4 | online version: https://news.fogproject.org/simplified-api-documentation/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # New-FogObject 9 | 10 | ## SYNOPSIS 11 | Create a new fog object with the api 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | New-FogObject [[-type] ] [[-jsonData] ] [[-IDofObject] ] [] 17 | ``` 18 | 19 | ## DESCRIPTION 20 | creates a new object such as a host or task 21 | 22 | ## EXAMPLES 23 | 24 | ### Example 1 25 | ```powershell 26 | PS C:\> {{ Add example code here }} 27 | ``` 28 | 29 | {{ Add example description here }} 30 | 31 | ## PARAMETERS 32 | 33 | ### -type 34 | the type of api object 35 | 36 | ```yaml 37 | Type: String 38 | Parameter Sets: (All) 39 | Aliases: 40 | 41 | Required: False 42 | Position: 1 43 | Default value: None 44 | Accept pipeline input: False 45 | Accept wildcard characters: False 46 | ``` 47 | 48 | ### -jsonData 49 | json data in json string for api call 50 | 51 | ```yaml 52 | Type: Object 53 | Parameter Sets: (All) 54 | Aliases: 55 | 56 | Required: False 57 | Position: 3 58 | Default value: None 59 | Accept pipeline input: False 60 | Accept wildcard characters: False 61 | ``` 62 | 63 | ### -IDofObject 64 | the id of the object 65 | 66 | ```yaml 67 | Type: String 68 | Parameter Sets: (All) 69 | Aliases: 70 | 71 | Required: False 72 | Position: 4 73 | Default value: None 74 | Accept pipeline input: False 75 | Accept wildcard characters: False 76 | ``` 77 | 78 | ### CommonParameters 79 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 80 | 81 | ## INPUTS 82 | 83 | ## OUTPUTS 84 | 85 | ## NOTES 86 | 87 | ## RELATED LINKS 88 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/docs/Remove-FogObject.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: fogapi-help.xml 3 | Module Name: fogapi 4 | online version: https://news.fogproject.org/simplified-api-documentation/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # Remove-FogObject 9 | 10 | ## SYNOPSIS 11 | Removes/Deletes a object via fog api 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Remove-FogObject [[-type] ] [[-jsonData] ] [[-IDofObject] ] [] 17 | ``` 18 | 19 | ## DESCRIPTION 20 | Calls a delete function via the api 21 | 22 | ## EXAMPLES 23 | 24 | ### Example 1 25 | ```powershell 26 | PS C:\> {{ Add example code here }} 27 | ``` 28 | 29 | {{ Add example description here }} 30 | 31 | ## PARAMETERS 32 | 33 | ### -type 34 | the type of api object 35 | 36 | ```yaml 37 | Type: String 38 | Parameter Sets: (All) 39 | Aliases: 40 | 41 | Required: False 42 | Position: 1 43 | Default value: None 44 | Accept pipeline input: False 45 | Accept wildcard characters: False 46 | ``` 47 | 48 | ### -jsonData 49 | json data in json string 50 | 51 | ```yaml 52 | Type: Object 53 | Parameter Sets: (All) 54 | Aliases: 55 | 56 | Required: False 57 | Position: 3 58 | Default value: None 59 | Accept pipeline input: False 60 | Accept wildcard characters: False 61 | ``` 62 | 63 | ### -IDofObject 64 | the id of the object 65 | 66 | ```yaml 67 | Type: String 68 | Parameter Sets: (All) 69 | Aliases: 70 | 71 | Required: False 72 | Position: 4 73 | Default value: None 74 | Accept pipeline input: False 75 | Accept wildcard characters: False 76 | ``` 77 | 78 | ### CommonParameters 79 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 80 | 81 | ## INPUTS 82 | 83 | ## OUTPUTS 84 | 85 | ## NOTES 86 | 87 | ## RELATED LINKS 88 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/docs/Remove-UsbMac.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: fogapi-help.xml 3 | Module Name: fogapi 4 | online version: https://forums.fogproject.org/topic/10837/usb-ethernet-adapter-mac-s-for-imaging-multiple-hosts-universal-imaging-nics-wired-nic-for-all-wireless-devices/14 5 | schema: 2.0.0 6 | --- 7 | 8 | # Remove-UsbMac 9 | 10 | ## SYNOPSIS 11 | A cmdlet that uses invoke-fogapi to remove a given list of usb mac address from a host 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Remove-UsbMac [[-usbMacs] ] [[-hostname] ] [[-macId] ] [] 17 | ``` 18 | 19 | ## DESCRIPTION 20 | When a wireless device is imaged with a usb ethernet adapter, it should be removed when it's done 21 | 22 | ## EXAMPLES 23 | 24 | ### EXAMPLE 1 25 | ``` 26 | Remove-UsbMacs -fogServer "foggy" -usbMacs @("01:23:45:67:89:10", "00:00:00:00:00:00") 27 | ``` 28 | 29 | ## PARAMETERS 30 | 31 | ### -usbMacs 32 | a string of mac addresses like this @("01:23:45:67:89:10", "00:00:00:00:00:00") 33 | 34 | ```yaml 35 | Type: String[] 36 | Parameter Sets: (All) 37 | Aliases: 38 | 39 | Required: False 40 | Position: 1 41 | Default value: None 42 | Accept pipeline input: False 43 | Accept wildcard characters: False 44 | ``` 45 | 46 | ### -hostname 47 | the hostname to remove the usb macs from, defaults to current hostname 48 | 49 | ```yaml 50 | Type: String 51 | Parameter Sets: (All) 52 | Aliases: 53 | 54 | Required: False 55 | Position: 2 56 | Default value: "$(hostname)" 57 | Accept pipeline input: False 58 | Accept wildcard characters: False 59 | ``` 60 | 61 | ### -macId 62 | {{ Fill macId Description }} 63 | 64 | ```yaml 65 | Type: Object 66 | Parameter Sets: (All) 67 | Aliases: 68 | 69 | Required: False 70 | Position: 3 71 | Default value: None 72 | Accept pipeline input: False 73 | Accept wildcard characters: False 74 | ``` 75 | 76 | ### CommonParameters 77 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 78 | 79 | ## INPUTS 80 | 81 | ## OUTPUTS 82 | 83 | ## NOTES 84 | online version of help goes to fog forum post where the idea was conceived 85 | There are try catch blocks so the original working code before the get, update, and remove functions existed can remain as a fallback 86 | 87 | ## RELATED LINKS 88 | 89 | [https://forums.fogproject.org/topic/10837/usb-ethernet-adapter-mac-s-for-imaging-multiple-hosts-universal-imaging-nics-wired-nic-for-all-wireless-devices/14](https://forums.fogproject.org/topic/10837/usb-ethernet-adapter-mac-s-for-imaging-multiple-hosts-universal-imaging-nics-wired-nic-for-all-wireless-devices/14) 90 | 91 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/docs/Set-FogInventory.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: fogapi-help.xml 3 | Module Name: fogapi 4 | online version: https://forums.fogproject.org/topic/10837/usb-ethernet-adapter-mac-s-for-imaging-multiple-hosts-universal-imaging-nics-wired-nic-for-all-wireless-devices/14 5 | schema: 2.0.0 6 | --- 7 | 8 | # Set-FogInventory 9 | 10 | ## SYNOPSIS 11 | Sets a fog hosts inventory 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Set-FogInventory [[-hostObj] ] [[-jsonData] ] [] 17 | ``` 18 | 19 | ## DESCRIPTION 20 | Sets the inventory of a fog host object to json data gotten from get-foginventory 21 | 22 | ## EXAMPLES 23 | 24 | ### Example 1 25 | ```powershell 26 | PS C:\> {{ Add example code here }} 27 | ``` 28 | 29 | {{ Add example description here }} 30 | 31 | ## PARAMETERS 32 | 33 | ### -hostObj 34 | the host object to set on 35 | 36 | ```yaml 37 | Type: Object 38 | Parameter Sets: (All) 39 | Aliases: 40 | 41 | Required: False 42 | Position: 1 43 | Default value: (Get-FogHost) 44 | Accept pipeline input: False 45 | Accept wildcard characters: False 46 | ``` 47 | 48 | ### -jsonData 49 | the jsondata with the inventory 50 | 51 | ```yaml 52 | Type: Object 53 | Parameter Sets: (All) 54 | Aliases: 55 | 56 | Required: False 57 | Position: 2 58 | Default value: (Get-FogInventory -hostObj $hostObj) 59 | Accept pipeline input: False 60 | Accept wildcard characters: False 61 | ``` 62 | 63 | ### CommonParameters 64 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 65 | 66 | ## INPUTS 67 | 68 | ## OUTPUTS 69 | 70 | ## NOTES 71 | 72 | ## RELATED LINKS 73 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/docs/Set-FogServerSettings.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: fogapi-help.xml 3 | Module Name: fogapi 4 | online version: https://forums.fogproject.org/topic/10837/usb-ethernet-adapter-mac-s-for-imaging-multiple-hosts-universal-imaging-nics-wired-nic-for-all-wireless-devices/14 5 | schema: 2.0.0 6 | --- 7 | 8 | # Set-FogServerSettings 9 | 10 | ## SYNOPSIS 11 | Set fog server settings 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Set-FogServerSettings [[-fogApiToken] ] [[-fogUserToken] ] [[-fogServer] ] 17 | [-interactive] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | Set the apitokens and server settings for api calls with this module 22 | the settings are stored in a json file in the current users roaming appdata ($ENV:APPDATA\FogApi) 23 | this is to keep it locked down and inaccessible to standard users 24 | and keeps the settings from being overwritten when updating the module 25 | 26 | ## EXAMPLES 27 | 28 | ### Example 1 29 | ```powershell 30 | PS C:\> {{ Add example code here }} 31 | ``` 32 | 33 | {{ Add example description here }} 34 | 35 | ## PARAMETERS 36 | 37 | ### -fogApiToken 38 | fog API token found at https://fog-server/fog/management/index.php?node=about&sub=settings under API System 39 | 40 | ```yaml 41 | Type: String 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: False 46 | Position: 1 47 | Default value: None 48 | Accept pipeline input: False 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -fogUserToken 53 | your fog user api token found in the user settings https://fog-server/fog/management/index.php?node=user&sub=list select your api enabled used and view the api tab 54 | 55 | ```yaml 56 | Type: String 57 | Parameter Sets: (All) 58 | Aliases: 59 | 60 | Required: False 61 | Position: 2 62 | Default value: None 63 | Accept pipeline input: False 64 | Accept wildcard characters: False 65 | ``` 66 | 67 | ### -fogServer 68 | your fog server hostname or ip address to be used for created the url used in api calls default is fog-server or fogServer 69 | 70 | ```yaml 71 | Type: String 72 | Parameter Sets: (All) 73 | Aliases: 74 | 75 | Required: False 76 | Position: 3 77 | Default value: None 78 | Accept pipeline input: False 79 | Accept wildcard characters: False 80 | ``` 81 | 82 | ### -interactive 83 | switch to make setting these an interactive process 84 | 85 | ```yaml 86 | Type: SwitchParameter 87 | Parameter Sets: (All) 88 | Aliases: 89 | 90 | Required: False 91 | Position: Named 92 | Default value: False 93 | Accept pipeline input: False 94 | Accept wildcard characters: False 95 | ``` 96 | 97 | ### CommonParameters 98 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 99 | 100 | ## INPUTS 101 | 102 | ## OUTPUTS 103 | 104 | ## NOTES 105 | 106 | ## RELATED LINKS 107 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/docs/Set-FogSnapins.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: fogapi-help.xml 3 | Module Name: fogapi 4 | online version: https://forums.fogproject.org/topic/10837/usb-ethernet-adapter-mac-s-for-imaging-multiple-hosts-universal-imaging-nics-wired-nic-for-all-wireless-devices/14 5 | schema: 2.0.0 6 | --- 7 | 8 | # Set-FogSnapins 9 | 10 | ## SYNOPSIS 11 | Sets a list of snapins to a host, appends to existing ones 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Set-FogSnapins [[-hostid] ] [[-pkgList] ] [[-dept] ] [] 17 | ``` 18 | 19 | ## DESCRIPTION 20 | Goes through a provided list variable and adds each matching snapin to the provided 21 | hostid 22 | 23 | ## EXAMPLES 24 | 25 | ### EXAMPLE 1 26 | ``` 27 | Set-FogSnapins -hostid (Get-FogHost).id -pkgList @('Office365','chrome','slack') 28 | ``` 29 | 30 | This would associate snapins that match the titles of office365, chrome, and slack to the provided host id 31 | they could then be deployed with start-fogsnapins 32 | 33 | ## PARAMETERS 34 | 35 | ### -hostid 36 | {{ Fill hostid Description }} 37 | 38 | ```yaml 39 | Type: Object 40 | Parameter Sets: (All) 41 | Aliases: 42 | 43 | Required: False 44 | Position: 1 45 | Default value: ((Get-FogHost).id) 46 | Accept pipeline input: False 47 | Accept wildcard characters: False 48 | ``` 49 | 50 | ### -pkgList 51 | {{ Fill pkgList Description }} 52 | 53 | ```yaml 54 | Type: Object 55 | Parameter Sets: (All) 56 | Aliases: 57 | 58 | Required: False 59 | Position: 2 60 | Default value: None 61 | Accept pipeline input: False 62 | Accept wildcard characters: False 63 | ``` 64 | 65 | ### -dept 66 | {{ Fill dept Description }} 67 | 68 | ```yaml 69 | Type: Object 70 | Parameter Sets: (All) 71 | Aliases: 72 | 73 | Required: False 74 | Position: 3 75 | Default value: None 76 | Accept pipeline input: False 77 | Accept wildcard characters: False 78 | ``` 79 | 80 | ### CommonParameters 81 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 82 | 83 | ## INPUTS 84 | 85 | ## OUTPUTS 86 | 87 | ## NOTES 88 | General notes 89 | 90 | ## RELATED LINKS 91 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/docs/Start-FogSnapins.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: fogapi-help.xml 3 | Module Name: fogapi 4 | online version: https://forums.fogproject.org/topic/10837/usb-ethernet-adapter-mac-s-for-imaging-multiple-hosts-universal-imaging-nics-wired-nic-for-all-wireless-devices/14 5 | schema: 2.0.0 6 | --- 7 | 8 | # Start-FogSnapins 9 | 10 | ## SYNOPSIS 11 | Starts all associated snapins of a host 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Start-FogSnapins [[-hostid] ] [[-taskTypeid] ] [] 17 | ``` 18 | 19 | ## DESCRIPTION 20 | Starts the allsnapins task on a provided hostid 21 | 22 | ## EXAMPLES 23 | 24 | ### EXAMPLE 1 25 | ``` 26 | Start-FogSnapins 27 | ``` 28 | 29 | will get the current hosts id and start all snapins on it 30 | 31 | ## PARAMETERS 32 | 33 | ### -hostid 34 | the hostid to start the task on 35 | 36 | ```yaml 37 | Type: Object 38 | Parameter Sets: (All) 39 | Aliases: 40 | 41 | Required: False 42 | Position: 1 43 | Default value: ((Get-FogHost).id) 44 | Accept pipeline input: False 45 | Accept wildcard characters: False 46 | ``` 47 | 48 | ### -taskTypeid 49 | the id of the task to start, defaults to 12 50 | 51 | ```yaml 52 | Type: Object 53 | Parameter Sets: (All) 54 | Aliases: 55 | 56 | Required: False 57 | Position: 2 58 | Default value: 12 59 | Accept pipeline input: False 60 | Accept wildcard characters: False 61 | ``` 62 | 63 | ### CommonParameters 64 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 65 | 66 | ## INPUTS 67 | 68 | ## OUTPUTS 69 | 70 | ## NOTES 71 | 72 | ## RELATED LINKS 73 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/docs/Update-FogObject.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: fogapi-help.xml 3 | Module Name: fogapi 4 | online version: https://forums.fogproject.org/topic/10837/usb-ethernet-adapter-mac-s-for-imaging-multiple-hosts-universal-imaging-nics-wired-nic-for-all-wireless-devices/14 5 | schema: 2.0.0 6 | --- 7 | 8 | # Update-FogObject 9 | 10 | ## SYNOPSIS 11 | Update/patch/edit api calls 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Update-FogObject [[-type] ] [[-jsonData] ] [[-IDofObject] ] [[-uri] ] 17 | [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | Runs update calls to the api 22 | 23 | ## EXAMPLES 24 | 25 | ### Example 1 26 | ```powershell 27 | PS C:\> {{ Add example code here }} 28 | ``` 29 | 30 | {{ Add example description here }} 31 | 32 | ## PARAMETERS 33 | 34 | ### -type 35 | the type of fog object 36 | 37 | ```yaml 38 | Type: String 39 | Parameter Sets: (All) 40 | Aliases: 41 | 42 | Required: False 43 | Position: 1 44 | Default value: None 45 | Accept pipeline input: False 46 | Accept wildcard characters: False 47 | ``` 48 | 49 | ### -jsonData 50 | the json data string 51 | 52 | ```yaml 53 | Type: Object 54 | Parameter Sets: (All) 55 | Aliases: 56 | 57 | Required: False 58 | Position: 3 59 | Default value: None 60 | Accept pipeline input: False 61 | Accept wildcard characters: False 62 | ``` 63 | 64 | ### -IDofObject 65 | The ID of the object 66 | 67 | ```yaml 68 | Type: String 69 | Parameter Sets: (All) 70 | Aliases: 71 | 72 | Required: False 73 | Position: 4 74 | Default value: None 75 | Accept pipeline input: False 76 | Accept wildcard characters: False 77 | ``` 78 | 79 | ### -uri 80 | The explicit uri to use 81 | 82 | ```yaml 83 | Type: String 84 | Parameter Sets: (All) 85 | Aliases: 86 | 87 | Required: False 88 | Position: 5 89 | Default value: None 90 | Accept pipeline input: False 91 | Accept wildcard characters: False 92 | ``` 93 | 94 | ### CommonParameters 95 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 96 | 97 | ## INPUTS 98 | 99 | ## OUTPUTS 100 | 101 | ## NOTES 102 | just saw this and just today was finding some issue with Update-fogobject 103 | The issue appears to be with the dynamic parameter variable I have in the function for the coreobjecttype. 104 | For some reason it is working when you call the function and brings up all the coreobject type choices but then the variable is being set to null when the function is running. 105 | Meaning that when function builds the uri it only gets 106 | http://fogserver/fog//id/edit 107 | instead of 108 | http://fogserver/fog/coreObjectType/id/edit 109 | 110 | So one workaround I will try to publish by the end of the day is adding an optional uri parameter to that function so that you can manually override it when neccesarry. 111 | Also I should really add more documentation to each of the functions instead of just having it all under Invoke-fogapi 112 | 113 | I also will add a try/catch block to invoke-fogapi for when invoke-restmethod fails and have it try invoke-webrequest. 114 | 115 | ## RELATED LINKS 116 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/docs/about_FogApi.md: -------------------------------------------------------------------------------- 1 | # FogApi 2 | 3 | ## about_FogApi 4 | 5 | # SHORT DESCRIPTION 6 | A module for managing FOG operations via powershell 7 | 8 | # LONG DESCRIPTION 9 | 10 | To install this module you need at least powershell v3, was created with 5.1 and intended to be cross platform compatible with powershell v6 11 | To Install this module follow these steps 12 | * Easiest method: Install from PSGallery https://www.powershellgallery.com/packages/FogApi `Install-Module -name fogApi` 13 | 14 | * Manual Method: 15 | * download the zip of this repo https://github.com/FOGProject/fog-community-scripts/archive/master.zip and extract it 16 | * Or clone the repo using your favorite git tool, you just need the FogApi Folder this readme is in 17 | * Copy the FogApi folder this Readme file is in to... 18 | * For Windows Powershell v3-v5.1 19 | * C:\Program Files\WindowsPowershell\Modules 20 | * For Windows Powershell v6+ 21 | * C:\Program Files\PowerShell\6-preview\Modules 22 | * 6-Preview may need to be replaced with whatever current version you have installed 23 | * For Linux Powershell v6+ 24 | * /opt/microsoft/powershell/6.1.0-preview.2/Modules 25 | * 6.1.0-preview.2 may need to be replaced with whatever current version you have installed 26 | * For Mac Powershell v6+ (untested) 27 | * /usr/local/microsoft/powershell/6.x/Modules 28 | * 6.x should be replaced with whatever most current version you are using 29 | * I haven't tested this on a mac, the module folder may be somewhere else 30 | this is based on where it is in other powershell 6 installs 31 | * Open a powershell command prompt (I always run as admin, unsure if it's required) 32 | * Run `Import-Module FogApi` 33 | 34 | The module is now installed. 35 | The first time you try to run a command the settings.json file will automatically open 36 | in notepad on windows, nano on linux, or TextEdit on Mac 37 | You can also open the settings.json file and edit it manually before running your first command. 38 | The default settings are explanations of where to find the proper settings since json can't have comments 39 | 40 | Once the settings are set you can have a jolly good time utilzing the fog documentation 41 | found here https://news.fogproject.org/simplified-api-documentation/ that was used to model the parameters 42 | 43 | i.e. 44 | 45 | Get-FogObject has a type param that validates to object, objectactivetasktype, and search as those are the options given in the documentation. 46 | Each of those types validates (which means autocompletion) to the core types listed in the documentation. 47 | So if you typed in `Get-FogObject -Type object -Object h` and then started hitting tab, it would loop through the possible core objects you can get from the api that start with 'h' such as history, host, etc. 48 | 49 | Unless you filter a get with a json body it will return all the results into a powershell object. That object is easy to work with to create other commands. Note: Full Pipeline support will come at a later time 50 | i.e. 51 | 52 | `$hosts = Get-FogObject -Type Object -CoreObject Host `# calls get on http://fog-server/fog/host to list all hosts 53 | Now you can search all your hosts for the one or ones you're looking for with powershell 54 | maybe you want to find all the hosts with 'IT' in the name (note '?' is an alias for Where-Object) 55 | `$ITHosts = $hosts.hosts | ? name -match 'IT';` 56 | 57 | Now maybe you want to change the image all of these computers use to one named 'IT-Image' 58 | You can edit the object in powershell with a foreach-object ('%' is an alias for foreach-object) 59 | `$updatedITHosts = $ITHosts | % { $_.imagename = 'IT-image'}` 60 | 61 | Then you need to convert that object to json and pass each object into one api call at a time. Which sounds complicated, but it's not, it's as easy as 62 | ``` 63 | $updateITHosts | % { 64 | $jsonData = $_ | ConvertTo-Json; 65 | Update-FogObject -Type object -CoreObject host -objectID $_.id -jsonData $jsonData; 66 | #successful result of updated objects properties 67 | #or any error messages will output to screen for each object 68 | } 69 | ``` 70 | 71 | This is just one small example of the limitless things you can do with the api and powershell objects. 72 | 73 | see also the fogforum thread for the module https://forums.fogproject.org/topic/12026/powershell-api-module/2 74 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/FogApi/docs/en-us/about_FogApi.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_fogapi 3 | 4 | SHORT DESCRIPTION 5 | A module for managing FOG operations via powershell 6 | 7 | LONG DESCRIPTION 8 | To install this module you need at least powershell v3, was created with 5.1 9 | and intended to be cross platform compatible with powershell v6 To Install 10 | this module follow these steps * Easiest method: Install from PSGallery 11 | https://www.powershellgallery.com/packages/FogApi `Install-Module -name 12 | fogApi` * Manual Method: 13 | * download the zip of this repo 14 | https://github.com/FOGProject/fog-community-scripts/archive/master.zip and 15 | extract it * Or clone the repo using your favorite git tool, you just 16 | need the FogApi Folder this readme is in * Copy the FogApi folder this 17 | Readme file is in to... * For Windows Powershell v3-v5.1 * 18 | C:\Program Files\WindowsPowershell\Modules * For Windows Powershell v6+ 19 | * C:\Program Files\PowerShell\6-preview\Modules * 20 | 6-Preview may need to be replaced with whatever current version you have 21 | installed * For Linux Powershell v6+ * 22 | /opt/microsoft/powershell/6.1.0-preview.2/Modules * 23 | 6.1.0-preview.2 may need to be replaced with whatever current version you 24 | have installed * For Mac Powershell v6+ (untested) * 25 | /usr/local/microsoft/powershell/6.x/Modules * 6.x should be 26 | replaced with whatever most current version you are using * I 27 | haven't tested this on a mac, the module folder may be somewhere else 28 | this is based on where it is in other powershell 6 installs * Open a 29 | powershell command prompt (I always run as admin, unsure if it's required) 30 | * Run `Import-Module FogApi` 31 | The module is now installed. The first time you try to run a command the 32 | settings.json file will automatically open in notepad on windows, nano on 33 | linux, or TextEdit on Mac You can also open the settings.json file and edit 34 | it manually before running your first command. The default settings are 35 | explanations of where to find the proper settings since json can't have comments 36 | Once the settings are set you can have a jolly good time utilzing the fog 37 | documentation found here 38 | https://news.fogproject.org/simplified-api-documentation/ that was used to 39 | model the parameters 40 | i.e. 41 | Get-FogObject has a type param that validates to object, 42 | objectactivetasktype, and search as those are the options given in the 43 | documentation. Each of those types validates (which means autocompletion) to 44 | the core types listed in the documentation. So if you typed in 45 | `Get-FogObject -Type object -Object h` and then started hitting tab, it 46 | would loop through the possible core objects you can get from the api that 47 | start with 'h' such as history, host, etc. 48 | Unless you filter a get with a json body it will return all the results into 49 | a powershell object. That object is easy to work with to create other 50 | commands. Note: Full Pipeline support will come at a later time i.e. 51 | `$hosts = Get-FogObject -Type Object -CoreObject Host `# calls get on 52 | http://fog-server/fog/host to list all hosts Now you can search all your 53 | hosts for the one or ones you're looking for with powershell maybe you want 54 | to find all the hosts with 'IT' in the name (note '?' is an alias for 55 | Where-Object) `$ITHosts = $hosts.hosts | ? name -match 'IT';` 56 | Now maybe you want to change the image all of these computers use to one 57 | named 'IT-Image' You can edit the object in powershell with a foreach-object 58 | ('%' is an alias for foreach-object) `$updatedITHosts = $ITHosts | % { 59 | $_.imagename = 'IT-image'}` 60 | Then you need to convert that object to json and pass each object into one 61 | api call at a time. Which sounds complicated, but it's not, it's as easy as 62 | 63 | $updateITHosts | % { 64 | $jsonData = $_ | ConvertTo-Json; 65 | Update-FogObject -Type object -CoreObject host -objectID $_.id -jsonData $jsonData; 66 | #successful result of updated objects properties 67 | #or any error messages will output to screen for each object 68 | } 69 | 70 | This is just one small example of the limitless things you can do with the 71 | api and powershell objects. 72 | see also the fogforum thread for the module 73 | https://forums.fogproject.org/topic/12026/powershell-api-module/2 74 | 75 | -------------------------------------------------------------------------------- /PowershellModules/FogApi/Readme.md: -------------------------------------------------------------------------------- 1 | To install this module you need at least powershell v3, was created with 5.1 and intended to be cross platform compatible with powershell v6 2 | To Install this module follow these steps 3 | * Easiest method: Install from PSGallery https://www.powershellgallery.com/packages/FogApi `Install-Module -name fogApi` 4 | 5 | * Manual Method: 6 | * download the zip of this repo https://github.com/FOGProject/fog-community-scripts/archive/master.zip and extract it 7 | * Or clone the repo using your favorite git tool, you just need the FogApi Folder this readme is in 8 | * Copy the FogApi folder this Readme file is in to... 9 | * For Windows Powershell v3-v5.1 10 | * C:\Program Files\WindowsPowershell\Modules 11 | * For Windows Powershell v6+ 12 | * C:\Program Files\PowerShell\6-preview\Modules 13 | * 6-Preview may need to be replaced with whatever current version you have installed 14 | * For Linux Powershell v6+ 15 | * /opt/microsoft/powershell/6.1.0-preview.2/Modules 16 | * 6.1.0-preview.2 may need to be replaced with whatever current version you have installed 17 | * For Mac Powershell v6+ (untested) 18 | * /usr/local/microsoft/powershell/6.x/Modules 19 | * 6.x should be replaced with whatever most current version you are using 20 | * I haven't tested this on a mac, the module folder may be somewhere else 21 | this is based on where it is in other powershell 6 installs 22 | * Open a powershell command prompt (I always run as admin, unsure if it's required) 23 | * Run `Import-Module FogApi` 24 | 25 | The module is now installed. 26 | The first time you try to run a command the settings.json file will automatically open 27 | in notepad on windows, nano on linux, or TextEdit on Mac 28 | You can also open the settings.json file and edit it manually before running your first command. 29 | The default settings are explanations of where to find the proper settings since json can't have comments 30 | 31 | Once the settings are set you can have a jolly good time utilzing the fog documentation 32 | found here https://news.fogproject.org/simplified-api-documentation/ that was used to model the parameters 33 | 34 | i.e. 35 | 36 | Get-FogObject has a type param that validates to object, objectactivetasktype, and search as those are the options given in the documentation. 37 | Each of those types validates (which means autocompletion) to the core types listed in the documentation. 38 | So if you typed in `Get-FogObject -Type object -Object h` and then started hitting tab, it would loop through the possible core objects you can get from the api that start with 'h' such as history, host, etc. 39 | 40 | Unless you filter a get with a json body it will return all the results into a powershell object. That object is easy to work with to create other commands. Note: Full Pipeline support will come at a later time 41 | i.e. 42 | 43 | `$hosts = Get-FogObject -Type Object -CoreObject Host `# calls get on http://fog-server/fog/host to list all hosts 44 | Now you can search all your hosts for the one or ones you're looking for with powershell 45 | maybe you want to find all the hosts with 'IT' in the name (note '?' is an alias for Where-Object) 46 | `$ITHosts = $hosts.hosts | ? name -match 'IT';` 47 | 48 | Now maybe you want to change the image all of these computers use to one named 'IT-Image' 49 | You can edit the object in powershell with a foreach-object ('%' is an alias for foreach-object) 50 | `$updatedITHosts = $ITHosts | % { $_.imagename = 'IT-image'}` 51 | 52 | Then you need to convert that object to json and pass each object into one api call at a time. Which sounds complicated, but it's not, it's as easy as 53 | ``` 54 | $updateITHosts | % { 55 | $jsonData = $_ | ConvertTo-Json; 56 | Update-FogObject -Type object -CoreObject host -objectID $_.id -jsonData $jsonData; 57 | #successful result of updated objects properties 58 | #or any error messages will output to screen for each object 59 | } 60 | ``` 61 | 62 | This is just one small example of the limitless things you can do with the api and powershell objects. 63 | 64 | see also the fogforum thread for the module https://forums.fogproject.org/topic/12026/powershell-api-module/2 65 | -------------------------------------------------------------------------------- /PowershellModules/Readme.md: -------------------------------------------------------------------------------- 1 | This is where a future cross-platform powershell module for controlling fog via the api 2 | and other built-in tools will be found. 3 | Sadly I won't have time to build it for a while. 4 | However as I create snippets of functions I will add them to the snippets folder in .psm1 formats 5 | If there are others that wish to help build on this, it would be appreciated, also very open to ideas. 6 | 7 | Some things I'm planning on are 8 | 9 | * a setup/config function for getting or manually setting the fog api token default values for all fog functions, as well as other universal things like fog server hostname, and an option of adding other stuff -COMPLETE 10 | * some not directly fog related but helpful functions like creating start layouts from pre-structured legacy start menu, imagePrep function (utilizes sysprep), functions to install helpful windows tools for imaging like the Imaging Configuration designer for provisioning packages and the System Image Manager for creating sysprep unattend files. -StartMenu startscreen layout module done 11 | * setup/config functions for getting and setting any fog configuration accessible via the api 12 | * a install-FogService function - COMPLETE -put it in the fogapi module 13 | * Deploying snapins on local or remote computers - COMPLETE using the fogapi module, examples not complete 14 | * viewing local and remote fog logs, imaging history, snapin history, etc. 15 | * Queuing all task types for local and remote computers 16 | * basically everything that can be done via the api but just invoked with easy to learn ps commands like Start-ImageDeploy, Start-ImageCapture, Start-SnapinDeploy, etc. - Chose to do this different by utilzing autocomplete oh options and is essentialy complete. Wrapper functions could be easily created from existing module 17 | * All of this with tab completion as well for the possible parameter options when known, such as the api object options host,group,task,etc. -COMPLETE 18 | * The goal will to have it be with powershell 6 so these commands will be able to used on windows, mac, and linux -Untested but probably complete 19 | 20 | -------------------------------------------------------------------------------- /PowershellModules/StartLayoutCreator/StartLayoutCreator.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FOGProject/fog-community-scripts/983d44341db32d33cffe3644379d8fd838a67c10/PowershellModules/StartLayoutCreator/StartLayoutCreator.psd1 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FOG Community Scripts 2 | A collection of scripts made by and for our users. All scripts in this repository are under the MIT license (see the LICENSE file). 3 | -------------------------------------------------------------------------------- /RenumberImageIDs/README.md: -------------------------------------------------------------------------------- 1 | ### Renumber Image IDs. Author: Wayne Workman. 2 | --- 3 | 4 | 5 | As you use your FOG Server over time creating and deleting images, your image IDs will continue to climb higher. 6 | For me, they have gotten nearly to 200 before. This utility will re-number all of your image ID numbers as 7 | well as re-set the auto-increment number. This utility will preserve all current image assignments to hosts, 8 | and will also give you a write-out of what was changed to what. Your new image IDs will begin with 1. 9 | 10 | This utility is subject to the fog-community-scripts license. 11 | 12 | -------------------------------------------------------------------------------- /RenumberImageIDs/renumberImageIDs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #----- MySQL Credentials -----# 4 | #Fog settings file. 5 | fogsettings="/opt/fog/.fogsettings" 6 | #If fogsettings exists, source it. 7 | if [[ -e "$fogsettings" ]]; then 8 | source $fogsettings 9 | else 10 | echo "The file $fogsettings was not found, this script needs that file. Is FOG installed?" 11 | exit 12 | fi 13 | 14 | 15 | #----- Begin Program -----# 16 | 17 | selectAllImageIDs="SELECT imageID FROM images ORDER BY imageID" 18 | selectLowestImageID="SELECT imageID FROM images ORDER BY imageID ASC LIMIT 1" 19 | selectHighestImageID="SELECT imageID FROM images ORDER BY imageID DESC LIMIT 1" 20 | 21 | options="-sN" 22 | if [[ $snmysqlhost != "" ]]; then 23 | options="$options -h$snmysqlhost" 24 | fi 25 | if [[ $snmysqluser != "" ]]; then 26 | options="$options -u$snmysqluser" 27 | fi 28 | if [[ $snmysqlpass != "" ]]; then 29 | options="$options -p$snmysqlpass" 30 | fi 31 | options="$options -D fog -e" 32 | 33 | 34 | #Information gathering. 35 | lowestID=$(mysql $options "$selectLowestImageID") 36 | highestID=$(mysql $options "$selectHighestImageID") 37 | newAutoIncrement=$((highestID + 1)) 38 | 39 | 40 | ####### Basic logic flow ######## 41 | 42 | #If there is an image id of 1, move it to the new auto increment number. 43 | #After re-numbering is complete, the new auto increment number will not be taken. 44 | #Then reset the auto-increment to the new auto increment number, which is the first free number. 45 | 46 | 47 | 48 | #Move any images that have an ID of 1 to the next free number. 49 | if [[ "$lowestID" -eq "1" ]]; then 50 | echo "-------------------" 51 | echo "Attempting to change Image ID $lowestID to $newAutoIncrement" 52 | mysql $options "UPDATE images SET imageID = $newAutoIncrement WHERE imageID = $lowestID" 53 | mysql $options "UPDATE imageGroupAssoc SET igaImageID = $newAutoIncrement WHERE igaImageID = $lowestID" 54 | mysql $options "UPDATE hosts SET hostImage = $newAutoIncrement WHERE hostImage = $lowestID" 55 | echo "Attempt completed" 56 | fi 57 | 58 | 59 | #Re-number all images sequentially. 60 | count=1 61 | mysql $options "$selectAllImageIDs" | while read imageID; do 62 | echo "-------------------" 63 | echo "Attempting to change Image ID $imageID to $count" 64 | mysql $options "UPDATE images SET imageID = $count WHERE imageID = $imageID" 65 | mysql $options "UPDATE imageGroupAssoc SET igaImageID = $count WHERE igaImageID = $imageID" 66 | mysql $options "UPDATE hosts SET hostImage = $count WHERE hostImage = $imageID" 67 | echo "Attempt completed" 68 | count=$((count + 1)) 69 | done 70 | 71 | 72 | #set new auto-increment. 73 | echo "-------------------" 74 | highestID=$(mysql $options "$selectHighestImageID") 75 | newAutoIncrement=$((highestID + 1)) 76 | echo "Attempting to change the auto_increment for the images table to $newAutoIncrement" 77 | mysql $options "ALTER TABLE images AUTO_INCREMENT = $newAutoIncrement" 78 | echo "Attempt completed" 79 | 80 | -------------------------------------------------------------------------------- /RenumberSnapinIDs/README.md: -------------------------------------------------------------------------------- 1 | ### Renumber Snapin IDs. Author: Wayne Workman & Tom Elliott 2 | --- 3 | 4 | 5 | As you use your FOG Server over time creating and deleting snapins, your snapin IDs will continue to climb higher. This utility will re-number all of your snapin ID numbers as well as re-set the auto-increment number. This utility will preserve all current snapin assignments to hosts, and will also give you a write-out of what was changed to what. Your new snapin IDs will begin with 1. 6 | 7 | This utility is subject to the fog-community-scripts license. 8 | 9 | -------------------------------------------------------------------------------- /RenumberSnapinIDs/renumberSnapinIDs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #----- MySQL Credentials -----# 4 | #Fog settings file. 5 | fogsettings="/opt/fog/.fogsettings" 6 | #If fogsettings exists, source it. 7 | if [[ -e "$fogsettings" ]]; then 8 | source $fogsettings 9 | else 10 | echo "The file $fogsettings was not found, this script needs that file. Is FOG installed?" 11 | exit 12 | fi 13 | 14 | 15 | 16 | 17 | #----- Begin Program -----# 18 | 19 | 20 | #These are the static queries that are used for information gathering. 21 | selectAllSnapinIDs="SELECT sID FROM snapins ORDER BY sID" 22 | selectLowestSnapinID="SELECT sID FROM snapins ORDER BY sID ASC LIMIT 1" 23 | selectHighestSnapinID="SELECT sID FROM snapins ORDER BY sID DESC LIMIT 1" 24 | 25 | #Here we build the mysql options properly based on what's set inside of the fogsettings file that we sourced earlier. 26 | options="-sN" 27 | if [[ $snmysqlhost != "" ]]; then 28 | options="$options -h$snmysqlhost" 29 | fi 30 | if [[ $snmysqluser != "" ]]; then 31 | options="$options -u$snmysqluser" 32 | fi 33 | if [[ $snmysqlpass != "" ]]; then 34 | options="$options -p$snmysqlpass" 35 | fi 36 | options="$options -D fog -e" 37 | 38 | #Information gathering. 39 | lowestID=$(mysql $options "$selectLowestSnapinID") #Get the lowest snapin ID. 40 | highestID=$(mysql $options "$selectHighestSnapinID") #Get the highest snapin ID. 41 | newAutoIncrement=$((highestID + 1)) #The next free ID is the highest ID + 1. 42 | 43 | ####### Basic logic flow ######## 44 | 45 | #If there is a snapin id of 1, move it to the newAutoIncrement number. This is to free the ID number "1" to simplify re-ordering. 46 | #Renumbering then selects all imageIDs from lowest to highest and moves them to the counting number. 47 | #I.E. 5 gets moved to 1. 22 gets moved to 2. 34 gets moved to 3. and so on. 48 | #After re-numbering is complete, we find out what the new highest imageID is, and add 1 to it to find the "new" newAutoIncrement number. 49 | #Then reset the auto-increment to the newAutoIncrement number. 50 | 51 | 52 | 53 | #Move any snapins that have an ID of 1 to the next free number. 54 | if [[ "$lowestID" -eq "1" ]]; then 55 | echo "-------------------" 56 | echo "Attempting to change Snapin ID $lowestID to $newAutoIncrement" 57 | mysql $options "UPDATE snapins SET sID = $newAutoIncrement WHERE sID = $lowestID" 58 | mysql $options "UPDATE snapinGroupAssoc SET sgaSnapinID = $newAutoIncrement WHERE sgaSnapinID = $lowestID" 59 | mysql $options "UPDATE snapinAssoc SET saSnapinID = $newAutoIncrement WHERE saSnapinID = $lowestID" 60 | echo "Attempt completed" 61 | fi 62 | 63 | 64 | #Re-number all snapins sequentially. 65 | count=1 66 | mysql $options "$selectAllSnapinIDs" | while read snapinID; do 67 | echo "-------------------" 68 | echo "Attempting to change Snapin ID $snapinID to $count" 69 | mysql $options "UPDATE snapins SET sID = $count WHERE sID = $snapinID" 70 | mysql $options "UPDATE snapinGroupAssoc SET sgaSnapinID = $count WHERE sgaSnapinID = $snapinID" 71 | mysql $options "UPDATE snapinAssoc SET saSnapinID = $count WHERE saSnapinID = $snapinID" 72 | echo "Attempt completed" 73 | count=$((count + 1)) 74 | done 75 | 76 | 77 | #set new auto-increment. 78 | echo "-------------------" 79 | highestID=$(mysql $options "$selectHighestSnapinID") 80 | newAutoIncrement=$((highestID + 1)) 81 | echo "Attempting to change the auto_increment for the snapins table to $newAutoIncrement" 82 | mysql $options "ALTER TABLE snapins AUTO_INCREMENT = $newAutoIncrement" 83 | echo "Attempt completed" 84 | -------------------------------------------------------------------------------- /StorageNodeManagementTools/README.md: -------------------------------------------------------------------------------- 1 | ### Storage Node Management Tools. Author: Wayne Workman 2 | --- 3 | 4 | 5 | This is a collection of scripts written to ease management of many FOG Storage nodes and also some scripts to help with automated fog testing. This script collection can manage as many Storage Nodes as you include in the settings.sh file. Output is short and simple, and gives a simple "Success" or "Failure" message for each node. If you get a failure message, the script will continue. Most scripts execute commands on all nodes in unison. 6 | 7 | These scripts are tested working on CentOS 7, Debian 8, Fedora 25, Ubuntu 14, Ubuntu 16. 8 | 9 | Do not use this script to update FOG on your main fog server, it must come first and therefore should be done manually. 10 | 11 | This script collection is dependent on ssh pki authentication being setup between the system doing the updates, and makes use of aliases. You may set these things up manually, or you may use a tool I created to do this for you. Find that tool at the below link: 12 | 13 | https://github.com/wayneworkman/ssh-pki-setup 14 | 15 | To setup the aliases and authentication manually, in your workstation home directory, create `.ssh/config` and create aliases here. Create an ssh key-pair, and place the public key on all nodes inside of `/root/.ssh/authorized_keys` There's a lot of internet documentation about creating ssh aliases and keypairs. Create the alaises exactly as the nodes are named in Virsh if you're using virsh. 16 | 17 | All files in this directory are subject to the fog-community-scripts license. 18 | -------------------------------------------------------------------------------- /StorageNodeManagementTools/initialFogGitPull.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | #Note: 5 | # Trying to run this on the fog repo with more than a few systems at a time across a small 6 | # internet pipe will likely result in a few of the nodes failing to clone. 7 | # You may install and use trickle, but it's not available by default on many OSs. 8 | # you can always download it and install it though, by copying the install script and then modifying the copy. 9 | # The command to clone fog using trickle would be: 10 | 11 | # trickle -sd 100 git clone https://github.com/FOGProject/fogproject.git /root/git/fogproject > /dev/null 2>&1 12 | 13 | # Just replace the existing git clone command with that and all nodes would download at 1,000Kbps, or 1Mbps. 14 | 15 | # If you're reading this after you've had a clone failure, just add a command at the begining to delete the clone, and to kill any git processes as well. Such as: 16 | 17 | # pkill -f git > /dev/null 2>&1;rm -rf /root/git/fogproject; 18 | 19 | 20 | 21 | 22 | 23 | 24 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 25 | source "$cwd/settings.sh" 26 | 27 | 28 | clear 29 | 30 | #Create hidden file for each node - for status reporting. 31 | for i in "${storageNodes[@]}" 32 | do 33 | echo "-1" > $cwd/.$i 34 | done 35 | 36 | #Start the commands going in unison. 37 | for i in "${storageNodes[@]}" 38 | do 39 | 40 | printf $(ssh -o ConnectTimeout=$sshTimeout $i "mkdir /root/git > /dev/null 2>&1;git clone https://github.com/FOGProject/fogproject.git /root/git/fogproject > /dev/null 2>&1;echo \$?") > $cwd/.$i & 41 | 42 | done 43 | 44 | #Initially set completion status to false in order to enter into the loop. 45 | complete="false" 46 | 47 | #Run this loop until completion isn't false. This is the outter loop. 48 | while [[ "$complete" == "false" ]]; do 49 | 50 | clear 51 | echo 52 | echo 53 | echo "Updating node operating systems." 54 | echo 55 | complete="true" 56 | #Loop through each node to check status, this is the inner loop. 57 | for i in "${storageNodes[@]}" 58 | do 59 | 60 | status=$(cat $cwd/.$i) 61 | if [[ "$status" == "-1" ]]; then 62 | echo "$i...waiting for return" 63 | complete="false" 64 | elif [[ "$status" == "0" ]]; then 65 | echo "$i...Success!" 66 | else 67 | echo "$i...Failure!" 68 | fi 69 | 70 | done #Inner loop done. 71 | sleep 1 #Update frequency. 72 | done #Outter loop done. 73 | 74 | 75 | #Cleanup after all is done. 76 | for i in "${storageNodes[@]}" 77 | do 78 | rm -f $cwd/.$i 79 | done 80 | 81 | 82 | #Say it's done. 83 | echo 84 | echo "Complete" 85 | echo 86 | -------------------------------------------------------------------------------- /StorageNodeManagementTools/installPackage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 3 | source "$cwd/settings.sh" 4 | 5 | #Packages are space seperated if there are multiple ones. 6 | #You must change the below line to what you need. 7 | packages="git svn" 8 | 9 | #example list of packages: 10 | #packages="lsof iftop git svn firewalld" 11 | 12 | clear 13 | 14 | #Create hidden file for each node - for status reporting. 15 | for i in "${storageNodes[@]}" 16 | do 17 | echo "-1" > $cwd/.$i 18 | done 19 | 20 | #Start the commands going in unison. 21 | for i in "${storageNodes[@]}" 22 | do 23 | 24 | printf $(ssh -o ConnectTimeout=$sshTimeout $i "yum install $packages -y > /dev/null 2>&1;echo \$?") > $cwd/.$i & 25 | 26 | done 27 | 28 | #Initially set completion status to false in order to enter into the loop. 29 | complete="false" 30 | 31 | #Run this loop until completion isn't false. This is the outter loop. 32 | while [[ "$complete" == "false" ]]; do 33 | 34 | clear 35 | echo 36 | echo 37 | echo "Installing packages: $packages" 38 | echo 39 | complete="true" 40 | #Loop through each node to check status, this is the inner loop. 41 | for i in "${storageNodes[@]}" 42 | do 43 | 44 | status=$(cat $cwd/.$i) 45 | if [[ "$status" == "-1" ]]; then 46 | echo "$i...waiting for return" 47 | complete="false" 48 | elif [[ "$status" == "0" ]]; then 49 | echo "$i...Success!" 50 | else 51 | echo "$i...Failure!" 52 | fi 53 | 54 | done #Inner loop done. 55 | sleep 1 #Update frequency. 56 | done #Outter loop done. 57 | 58 | 59 | 60 | #Cleanup after all is done. 61 | for i in "${storageNodes[@]}" 62 | do 63 | rm -f $cwd/.$i 64 | done 65 | 66 | 67 | #Say it's done. 68 | echo 69 | echo "Complete" 70 | echo 71 | 72 | 73 | -------------------------------------------------------------------------------- /StorageNodeManagementTools/rebootNodes.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 3 | source "$cwd/settings.sh" 4 | 5 | 6 | clear 7 | echo 8 | echo "Rebooting all nodes." 9 | echo 10 | sleep 1 11 | 12 | #Start the commands going in unison. 13 | for i in "${storageNodes[@]}" 14 | do 15 | 16 | printf "Issuing reboot command to $i..." 17 | ssh -o ConnectTimeout=$sshTimeout $i "shutdown +1 -r > /dev/null 2>&1" 18 | printf "Done\n" 19 | 20 | done 21 | howLongToWait=120 22 | echo 23 | echo "Sleeping for $howLongToWait seconds." 24 | sleep $howLongToWait 25 | 26 | 27 | 28 | #Initially set completion status to false in order to enter into the loop. 29 | complete="false" 30 | 31 | #Run this loop until completion isn't false. This is the outter loop. 32 | while [[ "$complete" == "false" ]]; do 33 | 34 | message="\n\nWaiting for nodes to come back online.\n\n" 35 | complete="true" 36 | #Loop through each node to check status, this is the inner loop. 37 | for i in "${storageNodes[@]}" 38 | do 39 | 40 | status="offline" 41 | status=$(ssh -o ConnectTimeout=$sshTimeout $i "echo up" 2> /dev/null) 42 | 43 | if [[ "$status" == "up" ]]; then 44 | message="$message${i}...is online!\n" 45 | else 46 | message="$message${i}...is offline.\n" 47 | complete="false" 48 | fi 49 | done #Inner loop done. 50 | 51 | clear 52 | printf "$message" 53 | sleep 1 #Update frequency. 54 | done #Outter loop done. 55 | 56 | 57 | 58 | 59 | #Say it's done. 60 | echo 61 | echo "Complete" 62 | echo 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /StorageNodeManagementTools/removePackage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 3 | source "$cwd/settings.sh" 4 | 5 | #Packages are space seperated if there are multiple ones. 6 | #You must change the below line to what you need. 7 | packages="mod_evasive" 8 | 9 | #example list of packages: 10 | #packages="lsof iftop git svn firewalld" 11 | 12 | clear 13 | 14 | #Create hidden file for each node - for status reporting. 15 | for i in "${storageNodes[@]}" 16 | do 17 | echo "-1" > $cwd/.$i 18 | done 19 | 20 | #Start the commands going in unison. 21 | for i in "${storageNodes[@]}" 22 | do 23 | 24 | printf $(ssh -o ConnectTimeout=$sshTimeout $i "yum remove $packages -y > /dev/null 2>&1;echo \$?") > $cwd/.$i & 25 | 26 | done 27 | 28 | #Initially set completion status to false in order to enter into the loop. 29 | complete="false" 30 | 31 | #Run this loop until completion isn't false. This is the outter loop. 32 | while [[ "$complete" == "false" ]]; do 33 | 34 | clear 35 | echo 36 | echo 37 | echo "Removing packages: $packages" 38 | echo 39 | complete="true" 40 | #Loop through each node to check status, this is the inner loop. 41 | for i in "${storageNodes[@]}" 42 | do 43 | 44 | status=$(cat $cwd/.$i) 45 | if [[ "$status" == "-1" ]]; then 46 | echo "$i...waiting for return" 47 | complete="false" 48 | elif [[ "$status" == "0" ]]; then 49 | echo "$i...Success!" 50 | else 51 | echo "$i...Failure!" 52 | fi 53 | 54 | done #Inner loop done. 55 | sleep 1 #Update frequency. 56 | done #Outter loop done. 57 | 58 | 59 | #Cleanup after all is done. 60 | for i in "${storageNodes[@]}" 61 | do 62 | rm -f $cwd/.$i 63 | done 64 | 65 | 66 | #Say it's done. 67 | echo 68 | echo "Complete" 69 | echo 70 | 71 | 72 | -------------------------------------------------------------------------------- /StorageNodeManagementTools/settings.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | #This is a list of all storage node aliases and are space seperated. There is no limit on the number of items. 5 | #You will need to modify the below line for any of the scripts in this directory to work. 6 | #storageNodes=( fogsite1 fogsite2 downtown uptown dallas houston floor1 floor2 japan uk ) 7 | storageNodes=( box1 box2 box3 box4 ) 8 | 9 | #The name of the linux KVM+libvirtd host and is only used for the snapshot related scripts: 10 | hostsystem="hostname" 11 | 12 | gitBranch="master" 13 | 14 | sshTimeout=5 #seconds to wait for ssh connection to be established when running remote commands. 15 | 16 | 17 | -------------------------------------------------------------------------------- /StorageNodeManagementTools/updateNodeFOGs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 3 | source "$cwd/settings.sh" 4 | 5 | 6 | clear 7 | 8 | #Create hidden file for each node - for status reporting. 9 | for i in "${storageNodes[@]}" 10 | do 11 | echo "-1" > $cwd/.$i 12 | done 13 | 14 | #Start the commands going in unison. 15 | for i in "${storageNodes[@]}" 16 | do 17 | 18 | printf $(ssh -o ConnectTimeout=$sshTimeout $i "cd /root/git/fogproject > /dev/null 2>&1;git reset --hard > /dev/null 2>&1;git pull > /dev/null 2>&1;git checkout $fogBranch > /dev/null 2>&1;cd bin > /dev/null 2>&1;./installfog.sh -y > /dev/null 2>&1;echo \$?") > $cwd/.$i & 19 | 20 | done 21 | 22 | #Initially set completion status to false in order to enter into the loop. 23 | complete="false" 24 | 25 | #Run this loop until completion isn't false. This is the outter loop. 26 | while [[ "$complete" == "false" ]]; do 27 | 28 | clear 29 | echo 30 | echo 31 | echo "Updating FOG on nodes." 32 | echo 33 | complete="true" 34 | #Loop through each node to check status, this is the inner loop. 35 | for i in "${storageNodes[@]}" 36 | do 37 | 38 | status=$(cat $cwd/.$i) 39 | if [[ "$status" == "-1" ]]; then 40 | echo "$i...waiting for return" 41 | complete="false" 42 | elif [[ "$status" == "0" ]]; then 43 | echo "$i...Success!" 44 | else 45 | echo "$i...Failure!" 46 | fi 47 | 48 | done #Inner loop done. 49 | sleep 1 #Update frequency. 50 | done #Outter loop done. 51 | 52 | 53 | #Cleanup after all is done. 54 | for i in "${storageNodes[@]}" 55 | do 56 | rm -f $cwd/.$i 57 | done 58 | 59 | 60 | #Say it's done. 61 | echo 62 | echo "Complete" 63 | echo 64 | 65 | 66 | -------------------------------------------------------------------------------- /StorageNodeManagementTools/updateNodeOSs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 3 | source "$cwd/settings.sh" 4 | 5 | 6 | clear 7 | 8 | #Create hidden file for each node - for status reporting. 9 | for i in "${storageNodes[@]}" 10 | do 11 | echo "-1" > $cwd/.$i 12 | done 13 | 14 | #Start the commands going in unison. 15 | for i in "${storageNodes[@]}" 16 | do 17 | if [[ $(ssh -o ConnectTimeout=$sshTimeout $i "command -v dnf > /dev/null 2>&1;echo \$?") -eq "0" ]]; then 18 | printf $(ssh -o ConnectTimeout=$sshTimeout $i "dnf update -y > /dev/null 2>&1;echo \$?") > $cwd/.$i & 19 | elif [[ $(ssh -o ConnectTimeout=$sshTimeout $i "command -v yum > /dev/null 2>&1;echo \$?") -eq "0" ]]; then 20 | printf $(ssh -o ConnectTimeout=$sshTimeout $i "yum update -y > /dev/null 2>&1;echo \$?") > $cwd/.$i & 21 | elif [[ $(ssh -o ConnectTimeout=$sshTimeout $i "command -v apt-get > /dev/null 2>&1;echo \$?") -eq "0" ]]; then 22 | printf $(ssh -o ConnectTimeout=$sshTimeout $i "apt-get -y update > /dev/null 2>&1;apt-get -y dist-upgrade > /dev/null 2>&1;echo \$?") > $cwd/.$i & 23 | else 24 | echo "Don't know how to update $i. Seems like it won't accept DNF, YUM, or APT-GET." 25 | fi 26 | done 27 | 28 | #Initially set completion status to false in order to enter into the loop. 29 | complete="false" 30 | 31 | #Run this loop until completion isn't false. This is the outter loop. 32 | while [[ "$complete" == "false" ]]; do 33 | 34 | clear 35 | echo 36 | echo 37 | echo "Updating node operating systems." 38 | echo 39 | complete="true" 40 | #Loop through each node to check status, this is the inner loop. 41 | for i in "${storageNodes[@]}" 42 | do 43 | 44 | status=$(cat $cwd/.$i) 45 | if [[ "$status" == "-1" ]]; then 46 | echo "$i...waiting for return" 47 | complete="false" 48 | elif [[ "$status" == "0" ]]; then 49 | echo "$i...Success!" 50 | else 51 | echo "$i...Failure!" 52 | fi 53 | 54 | done #Inner loop done. 55 | sleep 1 #Update frequency. 56 | done #Outter loop done. 57 | 58 | 59 | #Cleanup after all is done. 60 | for i in "${storageNodes[@]}" 61 | do 62 | rm -f $cwd/.$i 63 | done 64 | 65 | 66 | #Say it's done. 67 | echo 68 | echo "Complete" 69 | echo 70 | -------------------------------------------------------------------------------- /delete-extra-macs-on-host/README.md: -------------------------------------------------------------------------------- 1 | ## Author: Wayne Workman 2 | 3 | --- 4 | 5 | This is a simple BASH script that deletes all extra MACs associated with a particular host. 6 | In the script at the top, set the hostID and MAC that you want to keep associated with that hostID. 7 | All other MACs associated with that hostID will be deleted. 8 | 9 | Create a root crontab event. You will need to be root to do this. 10 | 11 | You can switch to root with: 12 | 13 | `sudo -i` 14 | 15 | Then enter into root's crontab with: 16 | 17 | `crontab -e` 18 | 19 | 20 | Add this line to the file to run the script every minute. The path should be the path to the script. 21 | 22 | `* * * * * /root/git/fog-community-scripts/delete-extra-macs-on-host/delete-extra-macs.sh` 23 | 24 | Or this to run every 3 minutes: 25 | 26 | `*/3 * * * * /root/git/fog-community-scripts/delete-extra-macs-on-host/delete-extra-macs.sh` 27 | 28 | Or once a day: 29 | 30 | `0 12 * * * /root/git/fog-community-scripts/delete-extra-macs-on-host/delete-extra-macs.sh` 31 | 32 | This tool is licensed under the fog community scripts license. 33 | 34 | -------------------------------------------------------------------------------- /delete-extra-macs-on-host/delete-extra-macs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #----- Settings -----# 4 | hostID="0" # Put the host's ID here. 5 | macToKeep="aa:bb:cc:dd:ee:ff" # Put the mac you want to keep here. 6 | 7 | 8 | 9 | 10 | #----- Get command paths -----# 11 | mysql=$(command -v mysql) 12 | 13 | 14 | 15 | #----- MySQL Credentials -----# 16 | source /opt/fog/.fogsettings 17 | 18 | 19 | 20 | #----- Queries ------# 21 | deleteExtraMacs="DELETE FROM hostMAC WHERE hmHostID = '${hostID}' AND hmMAC != '${macToKeep}'" 22 | 23 | 24 | 25 | #----- Build mysql options -----# 26 | options="-sN" 27 | [[ $snmysqlhost != "" ]] && options="$options -h${snmysqlhost}" 28 | [[ $snmysqluser != "" ]] && options="$options -u${snmysqluser}" 29 | [[ $snmysqlpass != "" ]] && options="$options -p${snmysqlpass}" 30 | options="$options -D fog -e" 31 | 32 | 33 | 34 | #----- Execute the command -----# 35 | $mysql $options "${deleteExtraMacs}" 36 | 37 | # Troubleshooting line, echos the command. 38 | # echo "$mysql $options \"${deleteExtraMacs}\"" 39 | -------------------------------------------------------------------------------- /delete-network-printers/README.md: -------------------------------------------------------------------------------- 1 | ### Delete all network printers. Author: Wayne Workman. 2 | --- 3 | 4 | This powershell script will delete all network printers installed locally 5 | that begin with the address '10.' and will delete all printer ports that 6 | begin with the address '10.' 7 | 8 | When a fog network printer is deployed with incorrect settings, or when 9 | it's deployed successfully and the end-user renames it or deletes it, 10 | the printer goes into this weird state where the user cannot use it, 11 | it does not show in 'Devices and Printers', but the fog client and the 12 | fog client helper say that it's already installed. When this happens, 13 | you can use this script to delete all network printers installed locally. 14 | Beware, all this script does is delete network printers. It does not 15 | re-add them. If all of your printers are configured correctly via FOG, 16 | after this script completes the FOG Client will add all printers back. 17 | This script can be deployed manually on an as-needed basis or via 18 | a snapin as needed. 19 | 20 | This utility is subject to the fog-community-scripts license. 21 | 22 | -------------------------------------------------------------------------------- /delete-network-printers/deleteNetworkPrinters.ps1: -------------------------------------------------------------------------------- 1 | 2 | Get-WmiObject -ComputerName localhost -Class Win32_printer | where { $_.portname -like '10.**' -or $_.portname -like '10.***' -and $_.local -eq 'TRUE'} | Select -ExpandProperty Name | ForEach-Object { rundll32 printui.dll,PrintUIEntry /dl /n "$_" } 3 | 4 | Remove-PrinterPort -Name "10.*" 5 | -------------------------------------------------------------------------------- /exportFromDB/README.md: -------------------------------------------------------------------------------- 1 | ### Author: Wayne Workman 2 | --- 3 | 4 | This script exports a table from MySQL into CSV format. Works good as long as the data does not have commas. 5 | 6 | How to use: 7 | 8 | 1. Edit the script to have the correct username, password, server FQDN or IP. 9 | 2. Set the desired table. 10 | 3. Run the script with ./exportTableToCSV.sh 11 | 12 | This script is subject to the fog-community-scripts license. 13 | 14 | 15 | -------------------------------------------------------------------------------- /exportFromDB/exportTableToCSV.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | snmysqluser='fogstorage' 4 | snmysqlpass='something' #The fogstorage pass goes here, git it from Web Interface -> FOG Configuration -> FOG Settings -> FOG Storage Nodes 5 | snmysqlhost='10.0.0.2' #Put your FOG Server's FQDN or IP here. 6 | database="fog" 7 | table="inventory" 8 | header="" 9 | csvFile="/root/output.csv" 10 | mysql=$(command -v mysql) #Get absolute path of mysql command. 11 | sed=$(command -v sed) #Get absolute path of sed. 12 | echo=$(command -v echo) #Get absolute path of echo. 13 | 14 | 15 | #Get the headers. 16 | $mysql -sN -u $snmysqluser -h $snmysqlhost -D $database -p${snmysqlpass} -e "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA=\"$database\" AND TABLE_NAME=\"$table\"" | $sed 's/\x09/,/g' | while read field; 17 | do 18 | 19 | if [[ -z $header ]]; then 20 | header="${field}" 21 | else 22 | header="${header},${field}" 23 | fi 24 | echo "$header" > $csvFile 25 | done 26 | 27 | 28 | 29 | #Get the rows, convert to comma seperated, read line by line. 30 | $mysql -sN -u $snmysqluser -h $snmysqlhost -D $database -p${snmysqlpass} -e "SELECT * FROM $table" | $sed 's/\x09/,/g' | while read line; 31 | do 32 | echo "$line" >> $csvFile 33 | done 34 | 35 | -------------------------------------------------------------------------------- /external_reporting/README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | This work has been moved to here: https://github.com/FOGProject/fogproject-aws-devops/tree/main/external_reporting -------------------------------------------------------------------------------- /fog-aws-testing/README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | This work has been moved to here: https://github.com/FOGProject/fogproject-aws-devops/tree/main/fog_testing -------------------------------------------------------------------------------- /fog-cli/README.md: -------------------------------------------------------------------------------- 1 | ### Author: Wayne Workman 2 | --- 3 | 4 | This is a collection of scripts that makeup FOG-CLI. These all interact with FOG's RESTful API. These are intended to simplify scripting and automating FOG activities. 5 | 6 | How to use: 7 | 8 | 1. Install Python (use Python 3) 9 | 2. Install the Python library "Requests". Link here: http://docs.python-requests.org/en/master/ 10 | 3. Setup profile by running `fog-config` 11 | 4. Start using the CLI. 12 | 13 | 14 | 15 | This project and all it's contained files are subject to the fog-community-scripts license. 16 | -------------------------------------------------------------------------------- /fog-cli/cli-init: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | from pathlib import Path 3 | import os 4 | import configparser 5 | home = str(Path.home()) 6 | if ( not os.path.isfile('home' + '/.fog/credentials')): 7 | print ("fog-cli is not configured, please run fog-config") 8 | else: 9 | Config = ConfigParser.ConfigParser() 10 | Config.read('home' + '/.fog/credentials') 11 | 12 | 13 | -------------------------------------------------------------------------------- /fog-cli/fog-config: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | from pathlib import Path 3 | import os 4 | import configparser 5 | import getpass 6 | config = configparser.ConfigParser() 7 | home = str(Path.home()) 8 | configdir = home + '/.fog' 9 | if not os.path.exists(configdir): 10 | os.makedirs(configdir) 11 | cfgfile = open(configdir + '/credentials',"w") 12 | # add the settings to the structure of the file, and write it out... 13 | username = input('What FOG username to use, if using toekns leave blank: ') 14 | if ( username ): 15 | password = getpass.getpass(prompt='What is the password for user ' + username + ': ') 16 | else: 17 | apitoken = input('What API Token to use: ') 18 | if ( apitoken ): 19 | userapitoken = input('What user API token to use: ') 20 | if ( username and password ): 21 | config.add_section('default') 22 | config.set('default','Username', username) 23 | config.set('default','Password', password) 24 | config.write(cfgfile) 25 | cfgfile.close() 26 | elif ( apitoken and userapitoken ): 27 | config.add_section('default') 28 | config.set('default','apitoken', apitoken) 29 | config.set('default','Password', userapitoken) 30 | config.write(cfgfile) 31 | cfgfile.close() 32 | -------------------------------------------------------------------------------- /fog-libvirtd-testing/.gitignore: -------------------------------------------------------------------------------- 1 | streaks/ 2 | -------------------------------------------------------------------------------- /fog-libvirtd-testing/README.md: -------------------------------------------------------------------------------- 1 | ### FOG Automated Testing. Author: Wayne Workman 2 | --- 3 | 4 | 5 | These scripts are designed to use ssh aliases with key-based authentication setup to a Linux KVM+Virsh host that is running several guest OSs for testing FOG. 6 | 7 | All VMs should have a snapshot called "clean" where the OS is installed, updated, ssh configured, `/root/.ssh/authorized_keys` configured, ssh root login permitted, `git` installed, and the fog repository located at `/root/git/fogproject` 8 | 9 | The scripts are designed to test all current FOG Branches. Before each round of tests, the "clean" snapshot is restored and then the OS is updated. Results are sent to a file. 10 | 11 | This project makes use of slacktee, an opensource tool that simplifies sending messages to slack. 12 | Project home page: https://github.com/course-hero/slacktee 13 | Fork: https://github.com/wayneworkman/slacktee 14 | 15 | 16 | File descriptions: 17 | 18 | * `settings.sh` Where all settings go. 19 | ** storageNodes are the alias names that must be configured in the controlling sever's `/root/.ssh/config` file, and ssh certificate-based authentication to the remote boxes root must be setup prior. 20 | ** hostsystem is the VM host that runs `libvirtd`, the open source package that helps manage Linux KVM VM guests. 21 | ** gitDir is the universal git directory on all boxes including the controlling one. 22 | ** osTimeout is the length of time alloted for OS updates to happen in. 23 | ** fogTimeout is the alloted amount of time for the FOG installer to complete before being left behind. 24 | ** sshTime is used for small ssh commands, it's an extra timeout on top of the built-in ssh timeout. 25 | ** report is where all the important results are stored. 26 | ** output is where more (and less important) results are stored - mostly for the admin to know where in the process the script is at. 27 | 28 | * `createSnapshots.sh` Creates snapshots of all nodes on the VM host using the specified name. If a snapshot already exists with this name, it's deleted. 29 | 30 | * `customCommand.sh` A utility script that can be used to get things straightened out on all the nodes at once. 31 | 32 | * `deleteSnapshot.sh` Deletes specified snapshot. 33 | 34 | * `installBranch.sh` Installs the specified branch. This file gets sent via SCP by `updateNodeFOGs.sh` and runs locally on the remote nodes, and returns altered exit codes to specify where a failure happened. 35 | 36 | * `rebootVMs.sh` the reliable way of rebooting all of the nodes. 37 | 38 | * `test_all.sh` The primary script. This is what you initiate to do a complete run. 39 | 40 | * `updateNodeFOGs.sh` this script pushes out `installBranch.sh` to all nodes and then tells it to run, it waits for the return code. On failure, it attempts to gather logs from the broken box. 41 | 42 | * `updateNodeOSs.sh` updates all node's OS. 43 | 44 | 45 | All files in this directory are subject to the fog-community-scripts license. 46 | -------------------------------------------------------------------------------- /fog-libvirtd-testing/cancelTasks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This script optionally accepts the hostID you want to cancel tasks on. 4 | # Requires that jq is installed. 5 | # If no host ID is supplied as an argument, all host's tasks are canceled. 6 | # Example usages: 7 | 8 | # Cancel all tasks: 9 | # ./cancelTasks.sh 10 | # Cancel all tasks for host 5: 11 | # ./cancelTasks.sh 5 12 | 13 | 14 | 15 | 16 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 17 | source "$cwd/settings.sh" 18 | 19 | 20 | if [[ -z $(command -v jq) ]]; then 21 | echo "This requires jq to be installed, exiting." 22 | exit 1 23 | fi 24 | 25 | #Get the host ID if present. If present, just delete host's tasks. Else, delete all tasks. 26 | if [[ -z $1 ]]; then 27 | echo "$(date +%x_%r) Canceling all tasks on \"$testServerIP\"" >> $output 28 | cmd="timeout $sshTimeout curl --silent -X DELETE -H 'content-type: application/json' -H 'fog-user-token: ${testServerUserToken}' -H 'fog-api-token: ${testServerApiToken}' http://${testServerIP}/fog/task/cancel -d '{\"typeID\": [1,2] }'" 29 | else 30 | hostID=$1 31 | echo "$(date +%x_%r) Canceling tasks for host \"$hostID\"" >> $output 32 | cmd="timeout $sshTimeout curl --silent -X GET -H 'content-type: application/json' -H 'fog-user-token: ${testServerUserToken}' -H 'fog-api-token: ${testServerApiToken}' http://${testServerIP}/fog/task/cancel -d '{\"hostID\": [${hostID}]}'" 33 | fi 34 | 35 | #Run the command. 36 | result=$(eval $cmd) 37 | 38 | 39 | -------------------------------------------------------------------------------- /fog-libvirtd-testing/captureImage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | # This script calls the API to capture from the specified host, and also restores a snapshot to that host at the VM layer. 5 | # Argument 1 must be a snapshot name 6 | # Argument 2 must be the vmGuest's name 7 | # Argument 3 must be the FOG ID of the guest. 8 | 9 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 10 | source "$cwd/settings.sh" 11 | 12 | 13 | 14 | #Ask for the snapshot name to be passed in. 15 | if [[ -z $1 ]]; then 16 | echo "$(date +%x_%r) No snapshot passed for argument 1, exiting." >> $output 17 | exit 18 | else 19 | snapshot=$1 20 | fi 21 | 22 | 23 | #Ask for the VM guest. 24 | if [[ -z $2 ]]; then 25 | echo "$(date +%x_%r) No vmGuest passed for argument 2, exiting." >> $output 26 | exit 27 | else 28 | vmGuest=$2 29 | fi 30 | 31 | 32 | #Ask for the FOG ID of the guest we are to use for capture. 33 | if [[ -z $3 ]]; then 34 | echo "$(date +%x_%r) No vmGuestFogID passed for argument 3, exiting." >> $output 35 | exit 36 | else 37 | vmGuestFogID=$3 38 | fi 39 | 40 | 41 | 42 | echo "$(date +%x_%r) Beginning capture testing. snapshot=\"${snapshot}\" vmGuest=\"${vmGuest}\" vmGuestFogID=\"${vmGuestFogID}"\" >> $output 43 | 44 | 45 | #Make the hosts directory for logs on the share. 46 | rm -rf ${shareDir}/${vmGuest} 47 | mkdir -p ${shareDir}/${vmGuest}/screenshots 48 | chown -R $sharePermissions $shareDir 49 | 50 | 51 | echo "$(date +%x_%r) Restoring snapshot \"$snapshot\" to \"$vmGuest\"" >> $output 52 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh snapshot-revert $vmGuest $snapshot" > /dev/null 2>&1 53 | 54 | 55 | 56 | #Gracefully shutdown VM incase it's on. 57 | if [[ $(ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh domstate $vmGuest") == "running" ]]; then 58 | echo "$(date +%x_%r) Asking \"$vmGuest\" to gracefully shutdown." >> $output 59 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh shutdown \"$vmGuest\" > /dev/null 2>&1 60 | sleep 30 61 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh destroy \"$vmGuest\" > /dev/null 2>&1 62 | else 63 | echo "$(date +%x_%r) \"$vmGuest\" is already shutdown." >> $output 64 | fi 65 | 66 | 67 | echo "$(date +%x_%r) Queuing the capture job on the server." >> $output 68 | 69 | #Queue the capture job with the test fog server. 70 | cmd="curl --silent -k --header 'content-type: application/json' --header 'fog-user-token: ${testServerUserToken}' --header 'fog-api-token: $testServerApiToken' http://${testServerIP}/fog/host/${vmGuestFogID}/task --data '{\"taskTypeID\":2,\"shutdown\": true}'" 71 | eval $cmd > /dev/null 2>&1 #Don't care that it says null. 72 | 73 | 74 | sleep 5 75 | 76 | #Start the VM. 77 | echo "$(date +%x_%r) Starting up \"$testHost1VM\" for capture." >> $output 78 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh start $testHost1VM" > /dev/null 2>&1 79 | 80 | echo "$(date +%x_%r) Waiting for capture to complete..." >> $output 81 | 82 | count=0 83 | #Need to monitor task progress somehow. 84 | while true; do 85 | nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "echo wakeup") 86 | nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "echo get ready") 87 | timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh screenshot $vmGuest /root/${vmGuest}_${count}.ppm" > /dev/null 2>&1 88 | timeout $sshTime scp -o ConnectTimeout=$sshTimeout $hostsystem:/root/${vmGuest}_${count}.ppm ${shareDir}/${vmGuest}/screenshots > /dev/null 2>&1 89 | timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "rm -f /root/${vmGuest}_${count}.ppm" > /dev/null 2>&1 90 | 91 | if [[ "$(timeout $sshTimeout $cwd/./getTaskStatus.sh $vmGuestFogID)" == "0" ]]; then 92 | echo "$(date +%x_%r) Image capture of \"$vmGuest\" completed in about \"$((count / 2))\" minutes." >> $output 93 | echo "Image capture of \"$vmGuest\" completed in about \"$((count / 2))\" minutes." >> $report 94 | break 95 | else 96 | count=$(($count + 1)) 97 | sleep $captureLimitUnit 98 | if [[ $count -gt $captureLimit ]]; then 99 | echo "$(date +%x_%r) Image capture of \"$vmGuest\" did not complete within $((captureLimit / 2)) minutes." >> $output 100 | echo "Image capture of \"$vmGuest\" did not complete within $((captureLimit / 2)) minutes." >> $report 101 | break 102 | fi 103 | fi 104 | done 105 | 106 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh destroy $vmGuest" > /dev/null 2>&1 107 | 108 | #Get capture logs. 109 | $cwd/./getImageLogs.sh $vmGuest capture 110 | 111 | sleep 5 112 | 113 | -------------------------------------------------------------------------------- /fog-libvirtd-testing/createSnapshots.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | # This script creates a new snapshot of the name passed in argument 1 for all $storageNodes in the settings.sh file. 5 | # If a snapshot of this name already exists, it is deleted. 6 | 7 | 8 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 9 | source "$cwd/settings.sh" 10 | 11 | 12 | #Ask for the snapshot name to be passed in. 13 | if [[ -z $1 ]]; then 14 | echo "$(date +%x_%r) No snapshotName passed for argument 1, exiting." >> $output 15 | exit 16 | else 17 | snapshotName=$1 18 | fi 19 | 20 | 21 | #Start the commands going in unison. 22 | for i in "${storageNodes[@]}" 23 | do 24 | nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "echo wakeup") 25 | nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "echo get ready") 26 | sleep 5 27 | echo "$(date +%x_%r) Creating snapshot $snapshotName for $i" >> $output 28 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh snapshot-delete $i $snapshotName > /dev/null 2>&1;virsh snapshot-create-as $i $snapshotName > /dev/null 2>&1" 29 | 30 | 31 | done 32 | 33 | 34 | -------------------------------------------------------------------------------- /fog-libvirtd-testing/customCommand.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #This is a custom command to send to all the nodes. Put your command in the "command" variable below. 4 | #Depending on if you want to use parameter expansion or not, you need to single or double quote, and escape properly. 5 | 6 | 7 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 8 | source "$cwd/settings.sh" 9 | 10 | command="echo 'I am up' > /dev/null 2>&1" 11 | 12 | 13 | #Create hidden file for each node - for status reporting. 14 | for i in "${storageNodes[@]}" 15 | do 16 | echo "-1" > $cwd/.$i 17 | done 18 | 19 | for i in "${storageNodes[@]}" 20 | do 21 | printf $(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $i "$command;echo \$?") > $cwd/.$i 22 | status=$(cat $cwd/.$i) 23 | if [[ "$status" == "-1" ]]; then 24 | echo "$i did not complete." 25 | elif [[ "$status" == "0" ]]; then 26 | echo "$i success." 27 | else 28 | echo "$i Failure!" 29 | fi 30 | done 31 | 32 | 33 | #Cleanup after all is done. 34 | for i in "${storageNodes[@]}" 35 | do 36 | rm -f $cwd/.$i 37 | done 38 | 39 | -------------------------------------------------------------------------------- /fog-libvirtd-testing/deleteSnapshots.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #This deletes the specified snapshot for all $storageNodes 4 | 5 | 6 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 7 | source "$cwd/settings.sh" 8 | 9 | 10 | #Ask for the snapshot name to be passed in. 11 | if [[ -z $1 ]]; then 12 | echo "$(date +%x_%r) No snapshotName passed for argument 1, exiting." >> $output 13 | exit 14 | else 15 | snapshotName=$1 16 | fi 17 | 18 | 19 | 20 | #Start the commands going in unison. 21 | for i in "${storageNodes[@]}" 22 | do 23 | nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "echo wakeup") 24 | nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "echo get ready") 25 | sleep 5 26 | echo "$(date +%x_%r) Deleting snapshot $snapshotName from $i" >> $output 27 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh snapshot-delete $i $snapshotName > /dev/null 2>&1" 28 | 29 | 30 | done 31 | 32 | 33 | -------------------------------------------------------------------------------- /fog-libvirtd-testing/deployImage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | # This deploys an image to the specified VM, with a specified FOG ID. 5 | # Required arguments are 1 the VM's name, 2 the VM's FOG ID. 6 | # This script will deploy the pre-associated image with these FOG hosts only. 7 | 8 | 9 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 10 | source "$cwd/settings.sh" 11 | 12 | # First argument is our vmname 13 | vmname="$1" 14 | # Second argument is the ID 15 | fogid="$2" 16 | 17 | # Ask for the VM guest name. 18 | if [[ -z $vmname ]]; then 19 | echo "$(date +%x_%r) No vmGuest name passed for argument 1, exiting." >> $output 20 | exit 21 | else 22 | vmGuest=$vmname 23 | fi 24 | 25 | # Ask for the FOG ID of the guest we are to use for deploy. 26 | if [[ -z $fogid ]]; then 27 | echo "$(date +%x_%r) No vmGuestFogID passed for argument 2, exiting." >> $output 28 | exit 29 | else 30 | vmGuestFogID=$fogid 31 | fi 32 | 33 | echo "$(date +%x_%r) Queuing deploy. vmGuest=\"${vmGuest}\" vmGuestFogID=\"${vmGuestFogID}"\" >> $output 34 | 35 | 36 | #Make the hosts directory for logs on the share. 37 | rm -rf ${shareDir}/${vmGuest} 38 | mkdir -p ${shareDir}/${vmGuest}/screenshots 39 | chown -R $sharePermissions $shareDir 40 | 41 | 42 | # Headers 43 | contenttype="-H 'Content-Type: application/json'" 44 | usertoken="-H 'fog-user-token: ${testServerUserToken}'" 45 | apitoken="-H 'fog-api-token: ${testServerApiToken}'" 46 | 47 | # Body to send 48 | body="'{\"taskTypeID\":1,\"shutdown\": true}'" 49 | 50 | # URL to call 51 | url="http://${testServerIP}/fog/host/${vmGuestFogID}/task" 52 | 53 | # Queue the deploy jobs with the test fog server. 54 | cmd="curl --silent -k ${contenttype} ${usertoken} ${apitoken} ${url} -d ${body}" 55 | eval $cmd >/dev/null 2>&1 # Don't care that it says null. 56 | 57 | 58 | sleep 5 59 | 60 | # Reset the VM forcefully. 61 | echo "$(date +%x_%r) Resetting \"${vmGuest}\" to begin deploy." >> ${output} 62 | ssh -o ConnectTimeout=${sshTimeout} ${hostsystem} "virsh start \"${vmGuest}\"" >/dev/null 2>&1 63 | 64 | 65 | count=0 66 | #Need to monitor task progress somehow. Once done, should exit. 67 | getStatus="${cwd}/getTaskStatus.sh ${vmGuestFogID}" 68 | while [[ ! $count -gt $deployLimit ]]; do 69 | status=$($getStatus) 70 | nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "echo wakeup") 71 | nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "echo get ready") 72 | timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh screenshot $vmGuest /root/${vmGuest}_${count}.ppm" > /dev/null 2>&1 73 | timeout $sshTime scp -o ConnectTimeout=$sshTimeout $hostsystem:/root/${vmGuest}_${count}.ppm ${shareDir}/${vmGuest}/screenshots > /dev/null 2>&1 74 | timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "rm -f /root/${vmGuest}_${count}.ppm" > /dev/null 2>&1 75 | 76 | if [[ $status -eq 0 ]]; then 77 | echo "$(date +%x_%r) Completed image deployment to \"${vmGuest}\" in about \"$((count / 2))\" minutes." >> ${output} 78 | echo "Completed image deployment to \"${vmGuest}\" in about \"$((count / 2))\" minutes." >> ${report} 79 | break 80 | fi 81 | let count+=1 82 | sleep $deployLimitUnit 83 | done 84 | if [[ $count -gt $deployLimit ]]; then 85 | echo "$(date +%x_%r) Image deployment did not complete within \"$((deployLimit / 2))\" minutes." >> ${output} 86 | echo "Image deployment did not complete within \"$((deployLimit / 2))\" minutes." >> ${report} 87 | fi 88 | nonsense=$(timeout ${sshTime} ssh -o ConnectTimeout=${sshTimeout} ${hostsystem} "echo wakeup") 89 | nonsense=$(timeout ${sshTime} ssh -o ConnectTimeout=${sshTimeout} ${hostsystem} "echo get ready") 90 | sleep 5 91 | ssh -o ConnectTimeout=${sshTimeout} ${hostsystem} "virsh destroy \"${vmGuest}\"" >/dev/null 2>&1 92 | 93 | 94 | -------------------------------------------------------------------------------- /fog-libvirtd-testing/getImageLogs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This is a utility script that retrieves a log file that postinit scripts create, 4 | # and moves it into a web directory for availibility to the general public. 5 | # Requires arguments. 6 | # 1. The testHost name. This is used for pathing, and is also integrated into the init scripts. 7 | # 2. Task Type, this is used to properly name the log file. 8 | 9 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 10 | source "$cwd/settings.sh" 11 | 12 | rightNow=$(date +%Y-%m-%d_%H-%M) 13 | 14 | testHost=$1 15 | if [[ -z $testHost ]]; then 16 | echo "$(date +%x_%r) Must provide the testHost to get logs from." >> $output. 17 | exit 18 | fi 19 | 20 | task=$2 21 | if [[ -z $task ]]; then 22 | echo "$(date +%x_%r) Must provide the task type for log storage purposes." >> $output 23 | exit 24 | fi 25 | 26 | 27 | if [[ -f ${shareDir}/${testHost}/var-log.tar ]]; then 28 | mv ${shareDir}/${testHost}/var-log.tar ${webdir}/${testHost}/${rightNow}_${task}_var-log.tar 29 | gzip ${webdir}/${testHost}/${rightNow}_${task}_var-log.tar 30 | echo "$(date +%x_%r) \"$testHost\" ${task} /var/log here: http://${domainName}${port}${netdir}/${testHost}/${rightNow}_${task}_var-log.tar.gz" >> $output 31 | else 32 | echo "$(date +%x_%r) \"$testHost\" ${task} /var/log could not be retrieved." >> $output 33 | echo "\"$testHost\" ${task} /var/log could not be retrieved." >> $report 34 | fi 35 | 36 | if [[ -f ${shareDir}/${testHost}/postinit.log ]]; then 37 | mv ${shareDir}/${testHost}/postinit.log ${webdir}/${testHost}/${rightNow}_${task}_postinit.log 38 | echo "$(date +%x_%r) \"$testHost\" ${task} postinit.log: http://${domainName}${port}${netdir}/${testHost}/${rightNow}_${task}_postinit.log" >> $output 39 | if [[ -e ${webdir}/${testHost}/postinit_sums.log ]]; then 40 | last=$(tail -n 1 ${webdir}/${testHost}/postinit_sums.log) 41 | fi 42 | sum=$(sha256sum ${webdir}/${testHost}/${rightNow}_${task}_postinit.log | cut -d' ' -f1) 43 | echo "$sum" >> ${webdir}/${testHost}/postinit_sums.log 44 | if [[ "$sum" == "$last" ]]; then 45 | echo "$(date +%x_%r) \"$testHost\" ${task} postinit.log checksum matches last one." >> $output 46 | echo "\"$testHost\" ${task} postinit.log checksum matches last one." >> $report 47 | else 48 | echo "$(date +%x_%r) \"$testHost\" ${task} postinit.log checksum does not match last one." >> $output 49 | echo "\"$testHost\" ${task} postinit.log checksum does not match last one." >> $report 50 | fi 51 | else 52 | echo "$(date +%x_%r) \"$testHost\" ${task} postinit.log could not be retrieved." >> $output 53 | echo "\"$testHost\" ${task} postinit.log could not be retrieved." >> $report 54 | fi 55 | 56 | if [[ -f ${shareDir}/${testHost}/postdownload.log ]]; then 57 | mv ${shareDir}/${testHost}/postdownload.log ${webdir}/${testHost}/${rightNow}_${task}_postdownload.log 58 | echo "$(date +%x_%r) \"$testHost\" ${task} postdownload.log: http://${domainName}${port}${netdir}/${testHost}/${rightNow}_${task}_postdownload.log" >> $output 59 | if [[ -e ${webdir}/${testHost}/postdownload_sums.log ]]; then 60 | last=$(tail -n 1 ${webdir}/${testHost}/postdownload_sums.log) 61 | fi 62 | sum=$(sha256sum ${webdir}/${testHost}/${rightNow}_${task}_postdownload.log | cut -d' ' -f1) 63 | echo "$sum" >> ${webdir}/${testHost}/postdownload_sums.log 64 | if [[ "$sum" == "$last" ]]; then 65 | echo "$(date +%x_%r) \"$testHost\" ${task} postdownload.log checksum matches last one." >> $output 66 | echo " \"$testHost\" ${task} postdownload.log checksum matches last one." >> $report 67 | else 68 | echo "$(date +%x_%r) \"$testHost\" ${task} postdownload.log checksum does not match last one." >> $output 69 | echo " \"$testHost\" ${task} postdownload.log checksum does not match last one." >> $report 70 | fi 71 | else 72 | echo "$(date +%x_%r) \"$testHost\" ${task} postdownload.log could not be retrieved." >> $output 73 | echo "\"$testHost\" ${task} postdownload.log could not be retrieved." >> $report 74 | fi 75 | 76 | #Screenshots. 77 | count=$(ls -1 ${shareDir}/${testHost}/screenshots/*.ppm 2>/dev/null | wc -l) 78 | if [[ $count -gt 0 ]]; then 79 | tar -czf ${webdir}/${testHost}/${rightNow}_${task}_screenshots.tar.gz -C ${shareDir}/${testHost}/screenshots . 80 | echo "$(date +%x_%r) \"$testHost\" ${task} screenshots: http://${domainName}${port}${netdir}/${testHost}/${rightNow}_${task}_screenshots.tar.gz" >> $output 81 | else 82 | echo "$(date +%x_%r) \"$testHost\" ${task} screenshots could be retrieved." >> $output 83 | echo "\"$testHost\" ${task} screenshots could be retrieved." >> $report 84 | 85 | fi 86 | 87 | 88 | 89 | #Get checksums of vm disks. 90 | #nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "echo wakeup") 91 | #nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "echo get ready") 92 | #sleep 5 93 | #sum=$(ssh -o ConnectTimeout=$sshTimeout $hostsystem "sha256sum ${testHostDisksDir}/${testHost}.qcow2 | cut -d' ' -f1") 94 | #if [[ -e ${webdir}/${testHost}/disk_sums.log ]]; then 95 | # last=$(tail -n 1 ${webdir}/${testHost}/disk_sums.log) 96 | #fi 97 | #echo "$sum" >> ${webdir}/${testHost}/disk_sums.log 98 | #if [[ "$sum" == "$last" ]]; then 99 | # echo "$(date +%x_%r) \"$testHost\" ${task} disk checksum matches last one." >> $output 100 | # echo " \"$testHost\" ${task} disk checksum matches last one." >> $report 101 | #else 102 | # echo "$(date +%x_%r) \"$testHost\" ${task} disk checksum does not match last one." >> $output 103 | # echo " \"$testHost\" ${task} disk checksum does not match last one." >> $report 104 | #fi 105 | 106 | 107 | #Cleanup. 108 | rm -rf ${shareDir}/${testHost} 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /fog-libvirtd-testing/getTaskStatus.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This script returns the number of tasks for a single host ID, or for all hosts. 4 | # Argument 1 is optional, the host ID. 5 | # If the host ID is provided, the number of tasks for that host is returned. 6 | # If the host ID is not provided, the total number of tasks is returned. 7 | 8 | # No tasks in queue returns '0' 9 | # Requires that jq is installed. 10 | 11 | 12 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 13 | source "$cwd/settings.sh" 14 | 15 | 16 | if [[ -z $(command -v jq) ]]; then 17 | echo "This requires jq to be installed, exiting." 18 | exit 1 19 | fi 20 | 21 | #Get the host ID if present. Having just a blank variable within brackets breaks it. 22 | if [[ -z $1 ]]; then 23 | cmd="timeout $sshTimeout curl --silent -X GET -H 'content-type: application/json' -H 'fog-user-token: ${testServerUserToken}' -H 'fog-api-token: ${testServerApiToken}' http://${testServerIP}/fog/task/active -d '{\"hostID\": }'" 24 | else 25 | hostID=$1 26 | cmd="timeout $sshTimeout curl --silent -X GET -H 'content-type: application/json' -H 'fog-user-token: ${testServerUserToken}' -H 'fog-api-token: ${testServerApiToken}' http://${testServerIP}/fog/task/active -d '{\"hostID\": [${hostID}]}'" 27 | fi 28 | 29 | #Run the command. 30 | result=$(eval $cmd) 31 | 32 | echo $result | jq '.count' 33 | 34 | 35 | -------------------------------------------------------------------------------- /fog-libvirtd-testing/getTestServerReady.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Script that gets the latest $branch (below) installed on the test fog server. 4 | 5 | 6 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 7 | source "$cwd/settings.sh" 8 | 9 | #We only test working. 10 | branch="working" 11 | 12 | 13 | #Start the server up. 14 | 15 | if [[ $(ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh domstate $testServerVMName") == "running" ]]; then 16 | echo "$(date +%x_%r) \"$testServerVMName\" already running." >> $output 17 | else 18 | echo "$(date +%x_%r) Starting up \"$testServerVMName\"" >> $output 19 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh start $testServerVMName > /dev/null 2>&1" 20 | sleep 60 21 | fi 22 | 23 | 24 | #Create hidden file for server - for status reporting. 25 | echo "-1" > $cwd/.$testServerSshAlias 26 | echo "$(date +%x_%r) Installing branch \"$branch\" onto \"$testServerSshAlias\"" >> $output 27 | 28 | #Kick the tires. It helps, makes ssh load into ram, makes the switch learn where the traffic needs to go. 29 | nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $testServerSshAlias "echo wakeup") 30 | nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $testServerSshAlias "echo get ready") 31 | 32 | #Start the installation process. 33 | timeout $sshTime scp -o ConnectTimeout=$sshTimeout $cwd/installBranch.sh $testServerSshAlias:/root/installBranch.sh 34 | printf $(timeout $fogTimeout ssh -o ConnectTimeout=$sshTimeout $testServerSshAlias "/root/./installBranch.sh $branch;echo \$?") > $cwd/.$testServerSshAlias 35 | timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $testServerSshAlias "rm -f /root/installBranch.sh" 36 | status=$(cat $cwd/.$testServerSshAlias) 37 | 38 | #Cleanup after all is done. 39 | rm -f $cwd/.$testServerSshAlias 40 | 41 | 42 | if [[ "$status" != "0" ]]; then 43 | echo "$(date +%x_%r) \"$testServerSshAlias\" failed to update fog to \"$branch\", exit code was \"$status\"" >> $output 44 | echo "\"$testServerSshAlias\" failed to update fog to \"$branch\", exit code was \"$status\"" >> $report 45 | exit $status 46 | fi 47 | 48 | echo "$(date +%x_%r) \"$testServerSshAlias\" updated fog to \"$branch\" successfully." >> $output 49 | echo "\"$testServerSshAlias\" updated fog to \"$branch\" successfully." >> $report 50 | 51 | 52 | 53 | #Push new postinit and postdownload scripts to the test server. 54 | echo "$(date +%x_%r) Sending new post scripts to \"$testServerSshAlias\"" >> $output 55 | nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $testServerSshAlias "echo wakeup") 56 | nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $testServerSshAlias "echo get ready") 57 | sleep 5 58 | timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $testServerSshAlias "rm -f /images/dev/postinitscripts/postinit.sh" > /dev/null 2>&1 59 | timeout $sshTime scp -o ConnectTimeout=$sshTimeout $cwd/postinit.sh $testServerSshAlias:/images/dev/postinitscripts/postinit.sh > /dev/null 2>&1 60 | timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $testServerSshAlias "chmod +x /images/dev/postinitscripts/postinit.sh" > /dev/null 2>&1 61 | timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $testServerSshAlias "rm -f /images/postdownloadscripts/postdownload.sh" > /dev/null 2>&1 62 | timeout $sshTime scp -o ConnectTimeout=$sshTimeout $cwd/postdownload.sh $testServerSshAlias:/images/postdownloadscripts/postdownload.sh > /dev/null 2>&1 63 | timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $testServerSshAlias "chmod +x /images/postdownloadscripts/postdownload.sh" > /dev/null 2>&1 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /fog-libvirtd-testing/green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FOGProject/fog-community-scripts/983d44341db32d33cffe3644379d8fd838a67c10/fog-libvirtd-testing/green.png -------------------------------------------------------------------------------- /fog-libvirtd-testing/installBranch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Automates installation of FOG. 4 | # Arguments: 5 | # $1 The branch to checkout/pull from. 6 | branch=$1 7 | # Returns Error code, will exit with same error code. 8 | # Error 1 = Failed to call script properly. 9 | # Error 2 = Failed to reset git. 10 | # Error 3 = Failed to pull git. 11 | # Error 4 = Failed to checkout git. 12 | # Error 5 = Failed to change directory. 13 | # Error 6 = Installation failed. 14 | # All else "success". 15 | usage() { 16 | local errCode=$1 17 | echo "Usage $0 " 18 | exit $errCode 19 | } 20 | [[ -z $branch ]] && exit 1 21 | export PATH="$PATH:/usr/bin/core_perl" 22 | cd /root/git/fogproject >/dev/null 2>&1 23 | stat=$? 24 | [[ ! $stat -eq 0 ]] && exit 5 25 | git reset --hard >/dev/null 2>&1 26 | stat=$? 27 | [[ ! $stat -eq 0 ]] && exit 2 28 | git pull >/dev/null 2>&1 29 | stat=$? 30 | [[ ! $stat -eq 0 ]] && exit 3 31 | git checkout $branch >/dev/null 2>&1 32 | stat=$? 33 | [[ ! $stat -eq 0 ]] && exit 4 34 | git pull >/dev/null 2>&1 35 | stat=$? 36 | [[ ! $stat -eq 0 ]] && exit 2 37 | cd bin >/dev/null 2>&1 38 | stat=$? 39 | [[ ! $stat -eq 0 ]] && exit 5 40 | ./installfog.sh -y >/dev/null 2>&1 41 | stat=$? 42 | [[ ! $stat -eq 0 ]] && exit 6 43 | exit 0 44 | -------------------------------------------------------------------------------- /fog-libvirtd-testing/orange.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FOGProject/fog-community-scripts/983d44341db32d33cffe3644379d8fd838a67c10/fog-libvirtd-testing/orange.png -------------------------------------------------------------------------------- /fog-libvirtd-testing/postdownload.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This is a postdownload script that just gathers some information about the local disks. 4 | # It puts this information onto a mounted share that the postinit should have accomplished. 5 | 6 | #Formulate filename. 7 | postDownloadOutput="/fogtesting/postdownload.log" 8 | touch $postDownloadOutput 9 | 10 | 11 | echo "#################### sfdisk -Fl /dev/sda" > $postDownloadOutput 12 | sfdisk -Fl /dev/sda >> $postDownloadOutput 13 | echo "" >> $postDownloadOutput 14 | echo "" >> $postDownloadOutput 15 | echo "#################### lsblk" >> $postDownloadOutput 16 | lsblk >> $postDownloadOutput 17 | echo "" >> $postDownloadOutput 18 | echo "" >> $postDownloadOutput 19 | echo "#################### blkid" >> $postDownloadOutput 20 | blkid >> $postDownloadOutput 21 | echo "" >> $postDownloadOutput 22 | echo "" >> $postDownloadOutput 23 | echo "#################### fdisk -l" >> $postDownloadOutput 24 | fdisk -l >> $postDownloadOutput 25 | echo "" >> $postDownloadOutput 26 | echo "" >> $postDownloadOutput 27 | echo "#################### pvdisplay" >> $postDownloadOutput 28 | pvdisplay >> $postDownloadOutput 29 | echo "" >> $postDownloadOutput 30 | echo "" >> $postDownloadOutput 31 | echo "#################### vgdisplay" >> $postDownloadOutput 32 | vgdisplay >> $postDownloadOutput 33 | echo "" >> $postDownloadOutput 34 | echo "" >> $postDownloadOutput 35 | echo "#################### lvdisplay" >> $postDownloadOutput 36 | lvdisplay >> $postDownloadOutput 37 | echo "" >> $postDownloadOutput 38 | echo "" >> $postDownloadOutput 39 | -------------------------------------------------------------------------------- /fog-libvirtd-testing/postinit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This is a postinit script that mounts a remote password protected CIFS/smb share. 4 | # It then starts and backgrounds a loop that packages up everything in /var/log to the share. 5 | # This constant log collecting just-about ensures you will get the crash log from FOS. 6 | # It also takes initial information about the local disks and puts that on the share. 7 | 8 | #Sourcing the functions file gives us access to all kernel variables and many neat functions. 9 | source /usr/share/fog/lib/funcs.sh 10 | 11 | #Mount share to /fogtesting 12 | 13 | mkdir /fogtesting 14 | mount -t cifs //10.0.0.25/fogtesting/$hostname /fogtesting -o username=fogtesting -o password=testing 15 | 16 | 17 | #Setup backgrounded loop that collects logs. 18 | loop="/backgroundloop.sh" 19 | echo "#!/bin/bash" > $loop 20 | echo "while true; do" >> $loop 21 | echo " if [[ -f /fogtesting/var-log.tar ]]; then" >> $loop 22 | echo " rm -f /fogtesting/var-log.tar" >> $loop 23 | echo " fi" >> $loop 24 | echo " tar -cf /fogtesting/var-log.tar -C /var/log ." >> $loop 25 | echo " sleep 25" >> $loop 26 | echo "done" >> $loop 27 | chmod +x $loop 28 | $loop & 29 | 30 | 31 | 32 | postInitOutput="/fogtesting/postinit.log" 33 | touch $postInitOutput 34 | 35 | echo "#################### sfdisk -Fl /dev/sda" > $postInitOutput 36 | sfdisk -Fl /dev/sda >> $postInitOutput 37 | echo "" >> $postInitOutput 38 | echo "" >> $postInitOutput 39 | echo "#################### lsblk" >> $postInitOutput 40 | lsblk >> $postInitOutput 41 | echo "" >> $postInitOutput 42 | echo "" >> $postInitOutput 43 | echo "#################### blkid" >> $postInitOutput 44 | blkid >> $postInitOutput 45 | echo "" >> $postInitOutput 46 | echo "" >> $postInitOutput 47 | echo "#################### fdisk -l" >> $postInitOutput 48 | fdisk -l >> $postInitOutput 49 | echo "" >> $postInitOutput 50 | echo "" >> $postInitOutput 51 | echo "#################### pvdisplay" >> $postInitOutput 52 | pvdisplay >> $postInitOutput 53 | echo "" >> $postInitOutput 54 | echo "" >> $postInitOutput 55 | echo "#################### vgdisplay" >> $postInitOutput 56 | vgdisplay >> $postInitOutput 57 | echo "" >> $postInitOutput 58 | echo "" >> $postInitOutput 59 | echo "#################### lvdisplay" >> $postInitOutput 60 | lvdisplay >> $postInitOutput 61 | echo "" >> $postInitOutput 62 | echo "" >> $postInitOutput 63 | -------------------------------------------------------------------------------- /fog-libvirtd-testing/rebootVMs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Script that reboots all $storageNodes VMs, and any stragglers that didn't want to reboot too. 4 | 5 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 6 | source "$cwd/settings.sh" 7 | 8 | nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "echo wakeup") 9 | nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "echo get ready") 10 | sleep 5 11 | 12 | #Gracefully shutdown all VMs. 13 | for i in "${storageNodes[@]}" 14 | do 15 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh shutdown $i > /dev/null 2>&1" 16 | sleep 3 17 | done 18 | sleep 10 19 | 20 | 21 | #force-off any stragglers. 22 | for i in "${storageNodes[@]}" 23 | do 24 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh destroy $i > /dev/null 2>&1" 25 | sleep 3 26 | done 27 | sleep 3 28 | 29 | 30 | 31 | #Start the VMs back up. 32 | for i in "${storageNodes[@]}" 33 | do 34 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh start $i > /dev/null 2>&1" 35 | sleep 5 36 | done 37 | howLongToWait=30 38 | sleep $howLongToWait 39 | 40 | 41 | 42 | #Initially set completion status to false in order to enter into the loop. 43 | complete="false" 44 | 45 | count=0 46 | #Run this loop until completion isn't false. This is the outter loop. 47 | while [[ "$complete" == "false" ]]; do 48 | 49 | complete="true" 50 | #Loop through each node to check status, this is the inner loop. 51 | for i in "${storageNodes[@]}" 52 | do 53 | 54 | status="offline" 55 | status=$(ssh -o ConnectTimeout=$sshTimeout $i "echo up" 2> /dev/null) 56 | 57 | if [[ "$status" != "up" ]]; then 58 | complete="false" 59 | echo "Waiting on \"$i\" to come back online..." >> $output 60 | fi 61 | done #Inner loop done. 62 | 63 | count=$(($count + 1)) 64 | if [[ $count -gt $rebootTimeout ]]; then 65 | break 66 | fi 67 | sleep 5 #Update frequency. 68 | done #Outter loop done. 69 | 70 | 71 | -------------------------------------------------------------------------------- /fog-libvirtd-testing/red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FOGProject/fog-community-scripts/983d44341db32d33cffe3644379d8fd838a67c10/fog-libvirtd-testing/red.png -------------------------------------------------------------------------------- /fog-libvirtd-testing/restoreSnapshots.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Script that restores a previous snapshot by name to all $storageNodes. 4 | # Requires argument: Snapshot name. 5 | 6 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 7 | source "$cwd/settings.sh" 8 | 9 | 10 | #Ask for the snapshot name to be passed in. 11 | if [[ -z $1 ]]; then 12 | echo "$(date +%x_%r) No snapshotName passed for argument 1, exiting." >> $output 13 | exit 14 | else 15 | snapshotName=$1 16 | fi 17 | 18 | 19 | 20 | 21 | for i in "${storageNodes[@]}" 22 | do 23 | nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "echo wakeup") 24 | nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "echo get ready") 25 | sleep 5 26 | echo "$(date +%x_%r) Restoring snapshot $snapshotName to $i" >> $output 27 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh snapshot-revert $i $snapshotName > /dev/null 2>&1" 28 | done 29 | 30 | 31 | -------------------------------------------------------------------------------- /fog-libvirtd-testing/setTestHostImages.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Script that sets the specified hosts to use the specified images. 4 | # Requires arguments: 5 | # 1. The Image ID. example: 5 6 | # 2. The hosts. Examples: 7 | # 1 8 | # 1,2,3 9 | # 1,3,5,7,9 10 | 11 | 12 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 13 | source "$cwd/settings.sh" 14 | 15 | 16 | #Get the image ID. 17 | if [[ -z $1 ]]; then 18 | echo "$(date +%x_%r) No image ID passed for argument 1, exiting." >> $output 19 | exit 1 20 | else 21 | imageID=$1 22 | fi 23 | 24 | 25 | #Get the host IDs. 26 | if [[ -z $2 ]]; then 27 | echo "$(date +%x_%r) No host IDs passed for argument 2, exiting." >> $output 28 | exit 1 29 | else 30 | hostIDs=$2 31 | fi 32 | 33 | 34 | echo "$(date +%x_%r) Setting FOG hosts \"$hostIDs\" image IDs to \"$imageID\"" >> $output 35 | 36 | #Set all the fog hosts to the same image. 37 | cmd="curl --silent -k -H 'Content-Type: application/json' -H 'fog-user-token: ${testServerUserToken}' -H 'fog-api-token: ${testServerApiToken}' http://${testServerIP}/fog/image/${imageID}/edit -X PUT -d '{\"hosts\": [${hostIDs}]}'" 38 | eval $cmd 39 | -------------------------------------------------------------------------------- /fog-libvirtd-testing/settings.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Get current working directory. 4 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 5 | 6 | #This is a list of all storage node aliases and are space seperated. There is no limit on the number of items. 7 | #You will need to modify the below line for any of the scripts in this directory to work. 8 | #SSH cert-based authentication and SSH Aliases need setup between the fogTesting box and all below storageNodes. 9 | storageNodes=( Arch CentOS7 Debian8 Debian9 Fedora28 Fedora29 Ubuntu18 Ubuntu17.10 Ubuntu16 Ubuntu14 ) 10 | 11 | #The name of the SSH alias for the linux KVM+libvirtd host: 12 | hostsystem="dl580" 13 | gitDir="/root/git" 14 | 15 | sshTimeout=15 #seconds to wait for ssh connection to be established when running remote commands. 16 | 17 | osTimeout="20m" #Time to wait for OS updates to complete. 18 | fogTimeout="20m" #Time to wait for FOG installation to complete. 19 | rebootTimeout="300" #seconds to wait for reboots to complete. 20 | sshTime="${sshTimeout}s" #Time to wait for small SSH commands to complete. 21 | 22 | captureLimitUnit="30" # Time to wait for captures to complete. 23 | captureLimit="60" #This is how long a capture has to get done measured by "captureLimitUnit". 24 | 25 | deployLimitUnit="30" # Time to wait for deployments to complete, is seconds. #Recommended not to change this, the math is tricky. 26 | deployLimit="180" #Measured in "deployLimitUnit" which is seconds. #Recommended not to change this, the math is tricky. 27 | 28 | report="/root/report.txt" #Where the short report goes. 29 | output="/root/output.log" #Where all output goes. 30 | installer_dashboard="/root/index.html" #The dashboard file before being moved to the web directory. 31 | imaging_dashboard="/root/imaging_dashboard.html" #The dashboard file before being moved to the web directory. 32 | redfile="red.png" #Red dot used for dashboard. 33 | orangefile="orange.png" #Orange dot used for dashboard. 34 | greenfile="green.png" #Green dot used for dashboard. 35 | red="\"Failure\"" #HTML for using the red dot. 36 | orange="\"Possible" #HTML for using orange dot. 37 | green="\"Success\"" #HTML for using the green dot. 38 | 39 | 40 | 41 | streakDir="/root/streaks" 42 | 43 | 44 | 45 | webdir="/var/www/html" #This is the web directory to put reports and file structure into. 46 | permissions="www-data:www-data" #What the web file's ownership should be. 47 | domainName="fogtesting.theworkmans.us" #Your domain name. 48 | netdir="" #This is the net directory, what gets added to the domain name to get to the webdir. 49 | port="" #The port, if any. If default, leave blank. 50 | 51 | #This is how you would use your Public IP instead of a domain name: 52 | #publicIP=$(/usr/bin/curl -s http://whatismyip.akamai.com/) 53 | #domainName=$publicIP 54 | 55 | #The local shared directory where postinitscripts and postdownloadscripts puts stuff. 56 | shareDir="/fogtesting" 57 | sharePermissions="fogtesting:fogtesting" 58 | 59 | 60 | 61 | #These settings are for the long-standing test FOG Server. It's for testing FOG Functionality. 62 | #SSH aliases and cert-based auth should be setup between the fogTesting box and this box. 63 | 64 | testServerUserToken="NTZhZDlhN2M0NTcxOGE0ZTdmZGU1YTVhZGRlNzBmNDIzNTI4MTc1NjdiYWYyMzZlZWQyOTgxMWEzNzUxZjllNWVjY2NmOTUxMmEzZTMwNzkyOGJiODlkNjQ5MWUxY2E5ODkzZDFiZGUxMDFiY2IxNjJkZDhmY2NlMzdiZjA0N2Q=" 65 | 66 | testServerApiToken="M2JhM2ViZmJhZDM1MmQ1MTU4NTNjMTNmZjY4YTY3MGUxMTZmNzgyMmQxYzlhOWMwMmRjMTg0NWNmYTE4MmZiY2FkNjFjYzY1ZjY5NGQ4ZTE1Yjk4ZTg5NTQ0YTBiYmIwYzFjYmFiNTFiYzkwZTQ0YzI5MzFlNWM0NzhmMzEyNTk=" 67 | 68 | testServerVMName="testServer" 69 | testServerIP="10.0.0.28" 70 | testServerSshAlias="testServer" 71 | 72 | 73 | #These are settings for a VM that will be used to test capture & deploy with, and other fog functionality. 74 | #It uses libvirtd & KVM style snapin management, rebooting, and should be set to boot to NIC first. 75 | #Further host testing should be done in postinitscripts and postdownloadscripts from here. 76 | #Snapshots should be prepared with various OSs and partition layouts for testHost1. 77 | #testHost2 should have a smaller disk, testHost3 should have a larger disk. 78 | #Because of multiple OSs being tested with one VM, it's not yet possible to test Snapins. 79 | 80 | testHost1VM="testHost1" 81 | testHost1ID="1" 82 | testHost1Disk="/data/pool0/testHost1.qcow2" 83 | 84 | testHost1Snapshot1="win10" 85 | testHost1ImageID="1" 86 | 87 | 88 | testHost2VM="testHost2" 89 | testHost2ID="2" 90 | 91 | testHost3VM="testHost3" 92 | testHost3ID="3" 93 | 94 | 95 | testHostDisksDir="/data/pool0" 96 | blankSnapshot="blank" 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /fog-libvirtd-testing/shutdownTestServer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Simple little utility script to shutdown the test fog server VM. 4 | 5 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 6 | source "$cwd/settings.sh" 7 | 8 | echo "$(date +%x_%r) Shutting down $testServerVMName" >> $output 9 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh shutdown $testServerVMName > /dev/null 2>&1" 10 | sleep 60 11 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh destroy $testServerVMName > /dev/null 2>&1" 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /fog-libvirtd-testing/shutdownVMs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Shuts down all VMs in $storageNodes. 4 | 5 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 6 | source "$cwd/settings.sh" 7 | 8 | nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "echo wakeup") 9 | nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "echo get ready") 10 | sleep 5 11 | 12 | #Gracefully shutdown all VMs. 13 | for i in "${storageNodes[@]}" 14 | do 15 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh shutdown $i > /dev/null 2>&1" 16 | sleep 5 17 | done 18 | sleep 30 19 | #force-off any stragglers. 20 | for i in "${storageNodes[@]}" 21 | do 22 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh destroy $i > /dev/null 2>&1" 23 | sleep 5 24 | done 25 | -------------------------------------------------------------------------------- /fog-libvirtd-testing/smb.conf: -------------------------------------------------------------------------------- 1 | #This is the smb.conf file used for setting up the fogtesting share, where postinit and postdownload put log files. 2 | 3 | security = user 4 | passdb backend = tdbsam 5 | unix charset = utf-8 6 | dos charset = cp932 7 | 8 | [fogtesting] 9 | path = /fogtesting 10 | read only = no 11 | create mode = 0777 12 | directory mode = 0777 13 | writable = yes 14 | valid users = fogtesting 15 | -------------------------------------------------------------------------------- /fog-libvirtd-testing/test_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 3 | source "$cwd/settings.sh" 4 | 5 | 6 | #Test the installer. 7 | $cwd/./test_install.sh 8 | 9 | #Test imaging. 10 | #$cwd/./test_imaging.sh 11 | 12 | 13 | #/usr/bin/rsync -r /var/www/html fogtesting:/var/www 14 | #ssh -o ConnectTimeout=$sshTimeout fogtesting "systemctl restart apache2 > /dev/null 2>&1" 15 | 16 | /usr/bin/s3cmd sync /var/www/html/ s3://fogtesting.theworkmans.us 17 | 18 | 19 | -------------------------------------------------------------------------------- /fog-libvirtd-testing/test_imaging.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 3 | source "$cwd/settings.sh" 4 | 5 | 6 | #Ensure jq is installed. 7 | if [[ -z $(command -v jq) ]]; then 8 | if [[ ! -z $(command -v dnf) ]]; then 9 | dnf -y install jq > /dev/null 2>&1 10 | elif [[ ! -z $(command -v yum) ]]; then 11 | yum -y install jq > /dev/null 2>&1 12 | elif [[ ! -z $(command -v apt-get) ]]; then 13 | apt-get -y install jq > /dev/null 2>&1 14 | elif [[ ! -z $(command -v pacman) ]]; then 15 | pacman --noconfirm --sync jq > /dev/null 2>&1 16 | else 17 | echo "Don't know how to install jq, please install it first." 18 | exit 1 19 | fi 20 | fi 21 | 22 | #If an old report exists here, delete it. 23 | if [[ -f $report ]]; then 24 | rm -f $report 25 | fi 26 | 27 | #If old output file exists, delete it. 28 | if [[ -f $output ]]; then 29 | rm -f $output 30 | fi 31 | 32 | #Make needed directories. 33 | mkdir -p ${webdir}/${testHost1VM} 34 | mkdir -p ${webdir}/${testHost2VM} 35 | mkdir -p ${webdir}/${testHost3VM} 36 | 37 | 38 | #Make sure test VMs are off. 39 | #Destory test hosts. 40 | echo "$(date +%x_%r) Making sure all testHosts are off." >> $output 41 | nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "echo wakeup") 42 | nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "echo get ready") 43 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh destroy $testHost1VM" > /dev/null 2>&1 44 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh destroy $testHost2VM" > /dev/null 2>&1 45 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh destroy $testHost3VM" > /dev/null 2>&1 46 | sleep 5 47 | 48 | 49 | #Here, we begin testing fog functionality. 50 | $cwd/./getTestServerReady.sh 51 | 52 | #Clear all existing tasks on test server. 53 | $cwd/./cancelTasks.sh 54 | 55 | #Set host images. 56 | $cwd/./setTestHostImages.sh $testHost1ImageID "${testHost1ID},${testHost2ID},${testHost3ID}" 57 | 58 | #Capture. 59 | $cwd/./captureImage.sh $testHost1Snapshot1 $testHost1VM $testHost1ID 60 | 61 | #Restore blank snapshots to the three test hosts. 62 | nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "echo wakeup") 63 | nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "echo get ready") 64 | sleep 5 65 | echo "$(date +%x_%r) Restoring snapshot \"$blankSnapshot\" to \"$testHost1VM\"" >> $output 66 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh snapshot-revert $testHost1VM $blankSnapshot" > /dev/null 2>&1 67 | sleep 5 68 | echo "$(date +%x_%r) Restoring snapshot \"$blankSnapshot\" to \"$testHost2VM\"" >> $output 69 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh snapshot-revert $testHost2VM $blankSnapshot" > /dev/null 2>&1 70 | sleep 5 71 | echo "$(date +%x_%r) Restoring snapshot \"$blankSnapshot\" to \"$testHost3VM\"" >> $output 72 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh snapshot-revert $testHost3VM $blankSnapshot" > /dev/null 2>&1 73 | sleep 5 74 | 75 | 76 | #Deploy image to the three test hosts with two minutes between each to allow for proper queuing. 77 | $cwd/./deployImage.sh $testHost1VM $testHost1ID & 78 | sleep 60 79 | $cwd/./deployImage.sh $testHost2VM $testHost2ID & 80 | sleep 60 81 | $cwd/./deployImage.sh $testHost3VM $testHost3ID & 82 | sleep 60 83 | 84 | 85 | echo "$(date +%x_%r) Waiting for image deployments to complete." >> $output 86 | 87 | count=6 88 | #Need to monitor task progress somehow. Once done, should exit. 89 | while true; do 90 | if [[ "$(timeout $sshTimeout $cwd/./getTaskStatus.sh)" == "0" ]]; then 91 | break 92 | else 93 | count=$(($count + 1)) 94 | sleep $deployLimitUnit 95 | if [[ $count -gt $deployLimit ]]; then 96 | #Kill the monitoring scripts if they are still running. 97 | pkill deployImage.sh 98 | break 99 | fi 100 | fi 101 | done 102 | 103 | sleep $(( $deployLimitUnit * 2 )) #Make this value double that of the unit of measurement. 104 | #This is so the logs from the backgrounded deployImage.sh appear in the right order. 105 | 106 | if [[ $count -gt $deployLimit ]]; then 107 | echo "$(date +%x_%r) All image deployments did not complete within ${deployLimit} minutes." >> $output 108 | else 109 | echo "$(date +%x_%r) All image deployments completed in about \"$((count / 2))\" minutes." >> $output 110 | echo "All image deployments completed in about \"$((count / 2))\" minutes." >> $report 111 | fi 112 | 113 | 114 | #Clear all existing tasks on test server. 115 | $cwd/./cancelTasks.sh 116 | 117 | #Destory test hosts, shutdown test server. 118 | echo "$(date +%x_%r) Shutting down all test hosts and test server." >> $output 119 | nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "echo wakeup") 120 | nonsense=$(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $hostsystem "echo get ready") 121 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh destroy $testHost1VM" > /dev/null 2>&1 122 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh destroy $testHost2VM" > /dev/null 2>&1 123 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh destroy $testHost3VM" > /dev/null 2>&1 124 | ssh -o ConnectTimeout=$sshTimeout $hostsystem "virsh shutdown $testServer" > /dev/null 2>&1 125 | 126 | 127 | #Make the imaging logs available. 128 | $cwd/./getImageLogs.sh $testHost1VM deploy 129 | $cwd/./getImageLogs.sh $testHost2VM deploy 130 | $cwd/./getImageLogs.sh $testHost3VM deploy 131 | 132 | 133 | echo "$(date +%x_%r) Testing complete." >> $output 134 | 135 | mkdir -p $webdir/reports 136 | chown -R $permissions $webdir 137 | rightNow=$(date +%Y-%m-%d_%H-%M) 138 | mv $output $webdir/reports/${rightNow}_image.log 139 | chown $permissions $webdir/reports/${rightNow}_image.log 140 | 141 | 142 | echo "Full Report: http://${domainName}${port}${netdir}/reports/${rightNow}_image.log" >> $report 143 | cat $report | slacktee.sh -p 144 | 145 | -------------------------------------------------------------------------------- /fog-libvirtd-testing/upCheck.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #This is a custom command to send to all the nodes. Put your command in the "command" variable below. 4 | #Depending on if you want to use parameter expansion or not, you need to single or double quote, and escape properly. 5 | 6 | 7 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 8 | source "$cwd/settings.sh" 9 | 10 | command="echo 'I am up' > /dev/null 2>&1" 11 | 12 | 13 | #Create hidden file for each node - for status reporting. 14 | for i in "${storageNodes[@]}" 15 | do 16 | echo "-1" > $cwd/.$i 17 | done 18 | 19 | for i in "${storageNodes[@]}" 20 | do 21 | printf $(timeout $sshTime ssh -o ConnectTimeout=$sshTimeout $i "$command;echo \$?") > $cwd/.$i 22 | status=$(cat $cwd/.$i) 23 | if [[ "$status" == "-1" ]]; then 24 | echo "$i did not complete." 25 | elif [[ "$status" == "0" ]]; then 26 | echo "$i success." 27 | else 28 | echo "$i Failure!" 29 | fi 30 | done 31 | 32 | 33 | #Cleanup after all is done. 34 | for i in "${storageNodes[@]}" 35 | do 36 | rm -f $cwd/.$i 37 | done 38 | 39 | -------------------------------------------------------------------------------- /fog-libvirtd-testing/updateSystems.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 3 | source "$cwd/settings.sh" 4 | 5 | 6 | $cwd/./restoreSnapshots.sh clean 7 | $cwd/./rebootVMs.sh 8 | $cwd/./customCommand.sh 9 | $cwd/./updateNodeOSs.sh 10 | $cwd/./rebootVMs.sh 11 | 12 | echo "complete" 13 | 14 | -------------------------------------------------------------------------------- /troubleshootingTools/README.md: -------------------------------------------------------------------------------- 1 | ### Troubleshooting Tools. Authors: Wayne Workman, Tom Elliott, and others. 2 | --- 3 | 4 | In this directory you will find troubleshooting related utilities. 5 | Currently, there is an information-gathering script that can assist you in 6 | gathering information about a fog system both to help yourself or to 7 | upload to the fog forums for review. 8 | 9 | Files in this directory are subject to the fog-community-scripts license. 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /troubleshootingTools/monitor-missing-primary-mac.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | #-----Get command paths-----# 5 | printf=$(command -v printf) 6 | ping=$(command -v ping) 7 | mysql=$(command -v mysql) 8 | date=$(command -v date) 9 | echo=$(command -v echo) 10 | tail=$(command -v tail) 11 | 12 | log="/root/troubleshooting.log" 13 | 14 | 15 | # If the troubleshooting log exists, this means we caught what we wanted so exit. 16 | if [[ -f $log ]]; then 17 | exit 18 | fi 19 | 20 | 21 | 22 | # Source the fogsettings file to get mysql credentials. 23 | source /opt/fog/.fogsettings 24 | 25 | 26 | #----- Queries ------# 27 | 28 | # Any queries you want to monitor would go here. Just make a new SQL query and assign it to a new variable. 29 | 30 | # This query tests for hosts that do not have a primary MAC address set. 31 | getHostsWithMissingPrimaryMac="SELECT hostID FROM hosts WHERE hostID NOT IN (SELECT hmHostID FROM hostMAC WHERE hmPrimary = '1');" 32 | getHostsWithMissingPrimaryMacCount="SELECT COUNT(hostID) FROM hosts WHERE hostID NOT IN (SELECT hmHostID FROM hostMAC WHERE hmPrimary = '1');" 33 | getLast50historyEntries="SELECT hText,hUser,hTime,hIP FROM history ORDER BY hTime DESC LIMIT 50;" 34 | 35 | 36 | #----- Build mysql options -----# 37 | options="-sN" 38 | if [[ "$snmysqlhost" != "" ]]; then 39 | options="$options -h$snmysqlhost" 40 | fi 41 | if [[ "$snmysqluser" != "" ]]; then 42 | options="$options -u$snmysqluser" 43 | fi 44 | if [[ "$snmysqlpass" != "" ]]; then 45 | options="$options -p$snmysqlpass" 46 | fi 47 | options="$options -D fog -e" 48 | 49 | 50 | 51 | # To iterate through multiple fields in a return, do something like this as an example: 52 | # $mysql $options "$getHostnames" | while read hostID hostName; do 53 | 54 | 55 | count=$($mysql $options "$getHostsWithMissingPrimaryMacCount") 56 | 57 | if [[ "$count" == "0" ]]; then 58 | exit 59 | #echo 60 | fi 61 | 62 | echo "Date & time: $($date)" >> $log 63 | 64 | $mysql $options "$getHostsWithMissingPrimaryMac" | while read hostID; do 65 | # Write out a log file saying which hosts 66 | echo "Found hostID '$hostID' without a primary MAC." >> $log 67 | #end loop 68 | done 69 | 70 | if [[ -d "/var/log/httpd" ]]; then 71 | echo "################################################" >> $log 72 | echo "Apache error log" >> $log 73 | echo "################################################" >> $log 74 | $tail -n 100 /var/log/httpd/error_log >> $log 75 | echo "################################################" >> $log 76 | echo "Apache access log" >> $log 77 | echo "################################################" >> $log 78 | $tail -n 100 /var/log/httpd/access_log >> $log 79 | fi 80 | if [[ -d "/var/log/apache2" ]]; then 81 | echo "################################################" >> $log 82 | echo "Apache error log" >> $log 83 | echo "################################################" >> $log 84 | $tail -n 100 /var/log/apache2/error.log >> $log 85 | echo "################################################" >> $log 86 | echo "Apache access log" >> $log 87 | echo "################################################" >> $log 88 | $tail -n 100 /var/log/apache2/access.log >> $log 89 | fi 90 | 91 | 92 | 93 | echo "################################################" >> $log 94 | echo "Last 50 history events" >> $log 95 | echo "################################################" >> $log 96 | 97 | echo "hText,hUser,hTime,hIP" >> $log 98 | $mysql $options "$getLast50historyEntries" | while read hText hUser hTime hIP; do 99 | echo "$hText,$hUser,$hTime,$hIP" >> $log 100 | done 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /troubleshootingTools/troubleshoot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | (( EUID != 0 )) && exec sudo -- "$0" "$@" 3 | linuxReleaseName=`lsb_release -a 2> /dev/null | grep "Distributor ID" | awk '{print $3,$4,$5,$6,$7,$8,$9}' | tr -d " "`; 4 | if [ -z "$linuxReleaseName" ]; then 5 | # Fall back incase lsb_release does not exist / fails - use /etc/issue over /etc/*release* 6 | linuxReleaseName=`cat /etc/issue /etc/*release* 2>/dev/null | head -n1 | awk '{print $1}'`; 7 | fi 8 | logfile="FOGtroubleshoot.log" 9 | # Delete logfile if it exists 10 | if [ -f $logfile ]; then 11 | rm $logfile 12 | fi 13 | #argument 1 is the logfile name 14 | getStatus() { 15 | i=1; 16 | if [ ! -z "`echo $linuxReleaseName | grep -Ei 'Fedora|Redhat|CentOS|Mageia'`" ]; then 17 | RHVER=`rpm -qa | grep release | xargs rpm -q --queryformat '%{VERSION}' | cut -c -1`; 18 | fi 19 | if [ "`echo $RHVER`" -gt 6 ]; then 20 | services="xinetd rpcbind nfs-server vsftpd firewalld FOGMulticastManager FOGSnapinReplicator FOGImageReplicator FOGScheduler"; 21 | nicename="TFTP RPCBind NFS FTP Firewall FOGMulticastManager FOGSnapinReplicator FOGImageReplicator FOGScheduler"; 22 | for service in $services; do 23 | niceval=`echo $nicename|awk '{print $'$i'}' |sed 's/_/ /'`; 24 | echo "----------------------$niceval status below" >> $1 25 | systemctl status $service >> $1; 26 | i=`expr $i '+' 1`; 27 | done 28 | else 29 | services="xinetd rpcbind nfs vsftpd iptables FOGMulticastManager FOGSnapinReplicator FOGImageReplicator FOGScheduler"; 30 | nicename="TFTP RPCBind NFS FTP Firewall FOGMulticastManager FOGSnapinReplicator FOGImageReplicator FOGScheduler"; 31 | for service in $services; do 32 | niceval=`echo $nicename|awk '{print $'$i'}' |sed 's/_/ /'`; 33 | echo "----------------------$niceval status below" >> $1 34 | service $service status >> $1; 35 | i=`expr $i '+' 1`; 36 | done 37 | fi 38 | } 39 | #argument 1 is the logfile name 40 | getLogs() { 41 | if [ ! -z "`echo $linuxReleaseName | grep -Ei 'Fedora|Redhat|CentOS|Mageia'`" ]; then 42 | httploc='httpd'; 43 | httpsep='_'; 44 | else 45 | httploc='apache2'; 46 | httpsep='.'; 47 | fi 48 | logs="/var/log/foginstall.log /var/log/${httploc}/error${httpsep}log /var/log/${httploc}/access${httpsep}log"; 49 | nicename="Installation Apache_Error Apache_Access"; 50 | i=1; 51 | for lfname in $logs; do 52 | if [ -f "$lfname" ]; then 53 | niceval=`echo $nicename|awk '{print $'$i'}' |sed 's/_/ /'`; 54 | echo ----------------------$niceval log below >> $1; 55 | tail -30 $lfname >> $1 56 | fi 57 | i=`expr $i '+' 1`; 58 | done 59 | } 60 | #argument 1 is the logfile name 61 | getConfs() { 62 | conffiles="/etc/dhcp/dhcpd.conf /etc/dnsmasq.d/ltsp.conf /etc/xinetd.d/tftp /etc/vsftpd/vsftpd.conf /etc/rc.d/rc.local"; 63 | for confname in $conffiles; do 64 | if [ -f "$confname" ]; then 65 | echo "----------------------$confname file below" >> $1; 66 | cat $confname >> $1; 67 | fi 68 | done 69 | } 70 | echo '----------------------'$linuxReleaseName' version below' >> $logfile 71 | cat /etc/issue >> $logfile 72 | if [ ! -z "`echo $linuxReleaseName | grep -Ei 'Fedora|Redhat|CentOS|Mageia'`" ]; then 73 | echo '----------------------SELinux status below' >> $logfile; 74 | sestatus >> $logfile 75 | fi 76 | echo '----------------------IP Configuration below' >> $logfile 77 | ip addr >> $logfile 78 | getStatus $logfile; 79 | getLogs $logfile; 80 | getConfs $logfile; 81 | storageLocation="/images"; 82 | if [ -d "/opt/fog" -a -f "/opt/fog/.fogsettings" ]; then 83 | . /opt/fog/.fogsettings; 84 | fi 85 | if [ -d "$storageLocation" ]; then 86 | echo '----------------------Check for /images/.mntcheck' >> $logfile 87 | ls $storageLocation -a |grep "mntcheck" >> $logfile 88 | echo '----------------------Check for /images/dev/.mntcheck' >> $logfile 89 | ls ${storageLocation}/dev -a |grep "mntcheck" >> $logfile 90 | echo '----------------------/images & file permissions below' >> $logfile 91 | ls -lR $storageLocation >> $logfile 92 | fi 93 | if [ -d "/tftpboot" ]; then 94 | echo '----------------------/tftpboot & file permissions below' >> $logfile 95 | ls -lR /tftpboot >> $logfile 96 | fi 97 | 98 | #convert output file to windows friendly text. 99 | sed -i 's/$/ /g' $logfile 100 | echo -n "Script Completed "; 101 | date 102 | echo "Your logfile can be found in `pwd`/$logfile"; 103 | -------------------------------------------------------------------------------- /updateIP/README.md: -------------------------------------------------------------------------------- 1 | ### Author: Wayne Workman 2 | --- 3 | 4 | This script updates FOG's IP address. It is designed for manual one-and-done use. If you're looking to automate changing a FOG Server's IP address, look at the MakeFogMobile project. 5 | 6 | How to use: 7 | 8 | 1. Update your operating system's IP Address according to your distribution's instructions. 9 | 2. Run `UpdateIP.sh` 10 | 11 | 12 | The project should work fine on: 13 | * Red Hat 7 14 | * CentOS 7 15 | * Fedora 19+ 16 | * Ubuntu 16 17 | * Debian 8 18 | * Raspbian Jessie+ 19 | 20 | Supports updating all the normal places: 21 | 22 | * `/tftpboot/default.ipxe` 23 | * Database entries 24 | * `config.class.php` 25 | * `/opt/fog/.fogsettings` 26 | 27 | Also - something new. Rebuilds DHCP Configuration from the ground-up for the new IP/network. Supports multi-nic and **multi-homed** configurations for DHCP. Supports detection/configuration for up to 4 network interfaces. 28 | 29 | -------------------------------------------------------------------------------- /updateIP/updateIP.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ##Get current working directory 4 | cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 5 | 6 | ##Source functions file. 7 | . $cwd/functions.sh 8 | 9 | # Variable definitions 10 | ## FOG Settings 11 | [[ -z $fogsettings ]] && fogsettings="/opt/fog/.fogsettings" 12 | ## Storage Node Name 13 | [[ -z $storageNode ]] && storageNode="DefaultMember" 14 | ## Database Name 15 | [[ -z $database ]] && database="fog" 16 | ## default.ipxe location 17 | [[ -z $tftpfile ]] && tftpfile="/tftpboot/default.ipxe" 18 | ## Get current directory 19 | [[ -z $DIR ]] && DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 20 | 21 | ##Clear screen. 22 | clear 23 | 24 | 25 | # Check fogsettings existence 26 | checkFilePresence "$fogsettings" 27 | checkFilePresence "$tftpfile" 28 | 29 | ## Source fogsettings file. 30 | . $fogsettings 31 | 32 | 33 | # Check our required checks first 34 | checkFogSettingVars "$interface" "interface" "$fogsettings" 35 | checkFogSettingVars "$ipaddress" "ipaddress" "$fogsettings" 36 | 37 | ##Get new interface/ip info. 38 | identifyInterfaces #Will exit on failure. Provides $newIP and $newInterface 39 | 40 | 41 | ## Do changes: 42 | updateIPinDB 43 | updateTFTP 44 | 45 | ## Check docroot and webroot is set 46 | checkFogSettingVars "$docroot" "docroot" "$fogsettings" 47 | checkFogSettingVars "$webroot" "docroot" "$fogsettings" 48 | 49 | ##Update config.class.php 50 | updateConfigClassPHP 51 | 52 | 53 | ##Have to update/restart ISC-DHCP here if it's supposed to be built/enabled in .fogsettings. 54 | ## Update ISC-DHCP 55 | configureDHCP 56 | 57 | 58 | ## Update fogsettings file. 59 | ## This must be done after the DHCP stuff so those related values are updated properly. 60 | updateFogsettings 61 | 62 | 63 | 64 | ##Only give message about DHCP/ProxyDHCP if "use dhcp" in fogsettings was disabled. 65 | printf "\n" 66 | printf "All done." 67 | if [[ "$dodhcp" == "N" || "$dodhcp" == "0" ]]; then 68 | printf " Don't forget to update your DHCP/ProxyDHCP to use: $newIP\n" 69 | else 70 | printf "\n" 71 | fi 72 | printf "\n" 73 | 74 | 75 | 76 | --------------------------------------------------------------------------------