Skip to content
Luca Dell'Oca Principal Cloud Architect @Veeam
Virtual To The Core Virtual To The Core

Virtualization blog, the italian way.

  • Media
  • About me
Virtual To The Core
Virtual To The Core

Virtualization blog, the italian way.

Configurare il monitoraggio via CIM su ESXi tramite powershell

Luca Dell'Oca, September 17, 2012December 4, 2016

Come in molti datacenter, utilizziamo software di monitoraggio per controllare i numerosi parametri della nostra infrastruttura. Grazie a CIM, è possibile usare direttamente queste APIs per monitorare l’hardware e lo stato di salute dei server ESXi, piuttosto che usare script e agent.

Nagios possiede alcuni ottimi plugin per usare CIM e monitorare ESXi, ma il problema è configurare correttamente le credenziali necessarie per accedere alle API CIM. Ho scoperto che William Lam ha già affrontato questo problema, e i suoi risultati sono stati raccolti in questo ottimo post.

Tuttavia, trovandomi più a mio agio con PowerShell piuttosto che Perl o Python, ho usato le sue scoperte per ricreare lo stesso script.

L’obiettivo, in entrambi i metodi, è di creare un utente che abbia i privilegi minimi indispensaili per leggere i dati CIM, in modo da garantire un ambiente protetto. Infatti, per default ESXi possiede solo questi ruoli locali:

PS C:> Get-VIRole

Name                      IsSystem
----                      --------
NoAccess                  True    
Anonymous                 True    
View                      True    
ReadOnly                  True    
Admin                     True

Se volete creare un utente per Nagios, dovrà possedere questo specifico privilegio:

Quindi, dovremo creare un nuovo ruolo che possieda solo questo privilegio, in modo da limitare al minimo l’interazione dell’utente nagios col sistema. Nello script di William, il privilegio viene invocato tramite il suo id, mentre in powershell dovrete usare il suo nome. Potete vedere il nome esatto nella schermata precedente, o verificarlo attraverso powershell (Get-VIPrivilege senza ulteriori argomenti vi da la lista completa):

PS C:> Get-VIPrivilege -Id Host.Cim.CimInteraction

Name                                Id                                 
----                                --                                 
CIM interaction                     Host.Cim.CimInteraction

Inoltre, come Williaw ha scoperto, l’utente dovrà far parte del gruppo root. Quindi, per cercare di limitarlo, lo script gli toglierà ogni accesso shell.

Questo è lo script completo PowerShell script. Con un semplice ciclo For potrete caricare una lista di server ESXi e configurarli tutti insieme.

## As usual, load needed PowerCLI cmdlets
asnp VMware.VimAutomation.Core -ErrorAction SilentlyContinue

# Define the ESXi server
$server = "server.domain.local"

#Connect to ESXi server
Connect-VIServer -Server $server -user root -password password

#Create a new role CIM, with the only needed privilege assigned to it
New-VIRole -Name CIM -Privilege "CIM interaction"

#Create the nagios account, assign it to root group, and deny it shell access
New-VMHostAccount -Id nagios -Description "nagios" -Password "password" -AssignGroups root -GrantShellAccess:$false

#Assign the role CIM to the newly created nagios account
New-VIPermission -Entity $server -Principal nagios -Role CIM

#Disconnect from ESXi server
Disconnect-VIServer -Server $server -Confirm:$false

 

 

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to email a link to a friend (Opens in new window) Email
  • Click to share on Tumblr (Opens in new window) Tumblr
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to share on Pocket (Opens in new window) Pocket
Tecnologia CIMesximonitoringnagiospowershell

Post navigation

Previous post
Next post

Search

Sponsors

Latest Posts

  • Migrate WSL (Windows Subsystem for Linux) to a new computer
  • Pass keystrokes to a pfSense virtual machine to install it automatically
  • Automatically deploy pfSense with Terraform and Ansible
  • My Automated Lab project: #6 Create a S3 Bucket with Terraform
  • My Automated Lab project: #5 Deploy a Linux vSphere VM with Terraform and custom disks
©2025 Virtual To The Core | WordPress Theme by SuperbThemes
We use cookies to ensure that we give you the best experience on our website, and to collect anonymous data regarding navigations stats using 3rd party plugins; they all adhere to the EU Privacy Laws. If you continue to use this site we will assume that you are ok with it.OkNoPrivacy Policy