├── .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]