Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Microsoft Hyper-V host sync with IT Glue #8

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

ecspresso
Copy link

Microsoft Hyper-V sync

This submission contains three scripts and one readme with instructions. The end result will sync the following to its asset in IT Glue:

  • Numbers of CPUs on the host
  • RAM in GB
  • Each HDD on the host and it's total/used/free space
  • Virtual switches
  • Numbers of VM guests
  • General information about each VM
  • Location of each VMs' virtual disks
  • Snapshot information
  • VMs' BIOS settings
  • Network information for each VM (NIC/IPv4/IPv6/MAC)

The script will look for changes on the host compared to IT Glue and only update if a change is detected, there is also an option to manually force an update by setting "Force manual sync now" to "Yes". It will try to match each VM against a configuration in the organization where the VM Host flexible asset resides. IT will first try matching via name and then via MAC address. If the matching succeeds, a clickable link will be created in place of its name. If the matching fails, the name will be in plain text. It will also create a related item for each matched configuration (and remove it again if the VM is deleted from the host).

ITGlue-VMHost-CreateFlexibleAsset.ps1

This script will create a flexible asset type to hold the data. You will need to create a flexible asset for each server to sync.

ITGlue-VMHost-Setup.ps1

This script will prepare the environment on the server by (if not already saved) saving the API key and data center location via the wrapper module settings and creating a scheduled task to run the syncing script once every day.

ITGlue-VMHost-FeedFlexibleAssetHyperV.ps1

This is the script that will do the actual syncing. It will not run unless you have at least PowerShell version 3 and ITGlueAPI PowerShell wrapper version 2.0.7 installed. How to run the script is each to their own and it is possible to provide all the parameters inside the script file but there is no need to edit this script if following the provided instructions.

hyperv-related-items.txt

This file is created by ITGlue-VMHost-FeedFlexibleAssetHyperV.ps1. Because there is no endpoint to get related items and their IDs, the file is created to store the last reponse from the endpoint create related items. The data is imported the next time the script is run if found and all current VMs are matched aganst IT Glue and then compared aginst old related items. All configurations no longer on the host are removed.

@Mondyro
Copy link

Mondyro commented Apr 22, 2020

Hi @ecspresso every time i try and run the script i am getting the following error and any assistance would be appreciated.

Set-ITGlueFlexibleAssets : {"errors":[{"status":422,"title":"Unprocessable Entity","detail":"Request contains invalid trait keys","source":{"pointer":"data/attributes/traits"}}]}
At C:\scripts\ITGLUEHyperV\ITGlue-VMHost-FeedFlexibleAssetHyperV.ps1:396 char:26

  • $response['asset'] = Set-ITGlueFlexibleAssets -data $asset_data
    
  •                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    • FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Set-ITGlueFlexibleAssets

@ecspresso
Copy link
Author

I looked at all the trait keys in both files, I think the problem is force manual sync. Either rename it in the asset to force manual sync now or change all the references in the sync script. It should be on line 314 and 347:
'force-manual-sync-now' = 'No' -> 'force-manual-sync' = 'No'
if($flexibleAsset.data.attributes.traits.'force-manual-sync-now' -eq 'Yes') { -> if($flexibleAsset.data.attributes.traits.'force-manual-sync -eq 'Yes') {

Let me know it if works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants