自從 Broadcom 收購 VMware 後,停止銷售新的永久授權,並改以訂閱制提供產品。這項變動讓許多原本使用 VMware 的 IT 團隊重新評估虛擬化平台的長期成本,也開始考慮將既有的虛擬機移轉到 Proxmox VE 虛擬化解決方案。
隨著越來越多團隊採用 Proxmox VE,iTop 團隊也推出了 Data Collector for Proxmox,讓管理者能自動將 Proxmox VE 的虛擬機資料同步到 iTop 的 CMDB,省去逐筆登錄與更新的工夫。

今天就來教大家如何透過 Data Collector for Proxmox 將 Proxmox 的資產相關組態自動整合到 iTop 之中。
Data Model for Proxmox
在使用 Data Collector 之前,我們必須先安裝 Data Model for Proxmox 擴充 iTop 的資料模型。
配置 Data Collector for Proxmox 連線設定
此外掛程式無法由 iTop Hub 自動安裝,您必須將其手動部署在運行 PHP 的伺服器上。
https://store.itophub.io/en_US/products/combodo-proxmox-data-collector

選擇最新的 1.1.1 Version,點選 Download。

將檔案的內容解壓縮到 iTop 目錄下的 Extensions 資料夾中
sudo unzip combodo-proxmox-data-collector-1_1_1.zip -d /var/www/html/itop/extensions
確保 Web 伺服器程序擁有足夠的權限來讀取新複製的檔案、目錄和子目錄。
sudo chown -R www-data:www-data /var/www/html/itop/extensions/combodo-proxmox-data-collector
請不要修改 Data Collector 預設的配置檔 params.distrib.xml,如果需要調整配置,請建立名為 params.local.xml 的文件,並將所需的定義複製,使兩個 XML 檔案的結構相同。
不要將 params.local.xml 存放在您的網頁伺服器目錄中,否則您的設定檔中的連線帳密可能外洩。
由於 Proxmox 或者 Cluster 通常不只一台以上,建議透過名稱的方式將配置檔分開來存放。
sudo cp /var/www/html/itop/extensions/combodo-proxmox-data-collector/conf/params.distrib.xml /etc/itop/params.proxmox.your_cluster_name.xml
編輯新增的組態文件
sudo nano /etc/itop/params.proxmox.your_cluster_name.xml
應包含用於連接到 iTop 伺服器和 Proxmox 的參數
<?xml version="1.0" encoding="UTF-8"?>
<!-- Default values for parameters. Do NOT alter this file, use params.local.xml instead -->
<parameters>
<itop_url>http://localhost/itop</itop_url>
<itop_login>your_itop_login</itop_login>
<itop_password>your_itop_password</itop_password>
<itop_token/>
<itop_login_mode/>
<!-- Connection Parameters -->
<proxmox_host>your_proxmox_ip</proxmox_host>
<proxmox_port>8006</proxmox_port>
<!-- Proxmox authentication: Use "ticket_cookie" or "api_tokens" -->
<proxmox_authentication_type>ticket_cookie</proxmox_authentication_type>
<proxmox_username>your_proxmox_username</proxmox_username>
<proxmox_password>your_proxmox_password</proxmox_password>
<!-- console_log_level: level of logging to console (std output)
-1 : none, nothing will be logged to the console
0 : System wide emergency errors only (LOG_EMERG)
1 : Alert errors (LOG_ALERT)
2 : Critical errors (LOG_CRIT)
3 : Application level errors (LOG_ERR)
4 : Warnings
5 : Notice
6 : Information
7 : Debug traces
-->
<console_log_level>6</console_log_level>
<!-- eventissue_log_level: level of creating event issue object on remote itop
-1 : none, nothing will be logged to the console
0 : System wide emergency errors only (LOG_EMERG)
1 : Alert errors (LOG_ALERT)
2 : Critical errors (LOG_CRIT)
3 : Application level errors (LOG_ERR)
4 : Warnings
5 : Notice
6 : Information
7 : Debug traces
-->
<eventissue_log_level>-1</eventissue_log_level>
<!--
dateformat: logging date format
Example: [Y-m-d H:i:s] => will produce a log like "[2020-04-29 14:36:16] [Info] ......"
-->
<console_log_dateformat>[Y-m-d H:i:s]</console_log_dateformat>
<!-- syslog_log_level: level of logging to Syslog
-1 : none, nothing will be logged to syslog
0 : System wide emergency errors (LOG_EMERG)
1 : Alert errors (LOG_ALERT)
2 : Critical errors (LOG_CRIT)
3 : Application level errors (LOG_ERR)
4 : Warnings
5 : Notice
6 : Information
7 : Debug traces
-->
<syslog_log_level>-1</syslog_log_level>
<!-- data_path: location where to store the temporary data (.raw and .csv files).
Make sure that you change this value if you run several instances of the collector
from the same location (with different configuration files).
You can use the placeholder %APPROOT% to build a path relative to the location of the collector itself
-->
<data_path>%APPROOT%/data/your_cluster_name</data_path>
<!-- Maximum number of elements to process in one iteration (for upload and synchro in iTop) -->
<max_chunk_size>1000</max_chunk_size>
<!-- Timeout for waiting for the execution of one data synchro task (in seconds) -->
<itop_synchro_timeout>600</itop_synchro_timeout>
<!-- Whether or not to stop when an error occurs during a synchronization -->
<stop_on_synchro_error>no</stop_on_synchro_error>
<!-- When using cUrl to connect to the iTop Webservices the cUrl options can be specified below
The syntax is:
<NAME_OF_THE_OPTION1>VALUE_OF_THE_OPTION1</NAME_OF_THE_OPTION1>
<NAME_OF_THE_OPTION2>VALUE_OF_THE_OPTION2</NAME_OF_THE_OPTION2>
etc...
Where NAME_OF_THE_OPTIONx and VALUE_OF_THE_OPTIONx are either:
- The numeric value of the option
- or the string representation of the corresponding PHP "define" (case sensitive)
The four examples below are equivalent:
<CURLOPT_SSLVERSION>CURL_SSLVERSION_TLSv1_2</CURLOPT_SSLVERSION>
or
<CURLOPT_SSLVERSION>6</CURLOPT_SSLVERSION>
or
<32>CURL_SSLVERSION_TLSv1_2</32>
or
<32>6</32>
Since in PHP we have:
define ('CURLOPT_SSLVERSION', 32);
define ('CURL_SSLVERSION_TLSv1_2', 6);
Note: because the recommandation about which is the best SSL/TLS version
to use varies over time (as security bugs are found in the procotols)
it is BETTER NOT TO force any SSL/TLS version at all and let the
system decide which version to use.
However if the web server running iTop requires a specific TLS/SSL
version you can use the configuration to force it anyway...
but be prepared to revisit this setting regularly.
-->
<curl_options>
<CURLOPT_SSL_VERIFYHOST>0</CURLOPT_SSL_VERIFYHOST>
<CURLOPT_SSL_VERIFYPEER>1</CURLOPT_SSL_VERIFYPEER>
</curl_options>
<!-- The email address of an existing contact in iTop, to be notified in case of error during the synchronization -->
<contact_to_notify></contact_to_notify>
<!-- iTop user set as allowed to run synchronization. It is highly recommended to use the same as itop_login. By default, it is the same as itop_login -->
<synchro_user></synchro_user>
<!-- date format in collected data -->
<date_format>Y-m-d H:i:s</date_format>
</parameters>
建立 Data Path 用來存放 ETL 產生的中繼檔案
sudo mkdir /var/www/html/itop/extensions/combodo-proxmox-data-collector/data/your_cluster_name
sudo chown -R www-data:www-data /var/www/html/itop/extensions/combodo-proxmox-data-collector/data/your_cluster_name
雖然上面的設定已經有指定 data_path 路徑 ,不過該套件還需要額外維護 jsonfile_path,否則您可能遇到下列錯誤訊息。
[Error] [iTopOSFamilyProxmoxCollector] Failed to get JSON file:
[Error] iTopOSFamilyProxmoxCollector::Prepare() returned false
還需要把 ignore_empty_json_source_file 改為 yes,這個設定會讓所有 Proxmox collector 接受空的來源。否則您可能遇到下列錯誤訊息。
[Error] [iTopPhysicalInterfaceProxmoxCollector] Failed to find path data until data in json file: /var/www/html/itop/extensions/combodo-proxmox-data-collector/data/your_cluster_name/ProxmoxPhysicalInterfaces.json.
[Error] iTopPhysicalInterfaceProxmoxCollector::Prepare() returned false
加入內容進行覆寫
<!-- Global parameters -->
<jsonfile_path>/var/www/html/itop/extensions/combodo-proxmox-data-collector/data/your_cluster_name</jsonfile_path>
<manage_ipv6>no</manage_ipv6>
<ignore_empty_json_source_file>yes</ignore_empty_json_source_file>
最後這個套件沒有支援 default_org_id,會造成物件沒有建立。
需要替下列物件添加 org_id 進行覆寫
<!-- IPv4 Address -->
<itopipv4addressproxmoxcollector>
<defaults>
<org_id>your_organization_name</org_id>
</defaults>
</itopipv4addressproxmoxcollector>
<!-- IPv6 Address -->
<itopipv6addressproxmoxcollector>
<defaults>
<org_id>your_organization_name</org_id>
</defaults>
</itopipv6addressproxmoxcollector>
<!-- ProxmoxClusters -->
<itopproxmoxclusterproxmoxcollector>
<defaults>
<org_id>your_organization_name</org_id>
</defaults>
</itopproxmoxclusterproxmoxcollector>
<!-- ProxmoxDisks -->
<itopproxmoxdiskproxmoxcollector>
<defaults>
<org_id>your_organization_name</org_id>
</defaults>
</itopproxmoxdiskproxmoxcollector>
<!-- Proxmox HA Group -->
<itopproxmoxhagroupproxmoxcollector>
<defaults>
<org_id>your_organization_name</org_id>
</defaults>
</itopproxmoxhagroupproxmoxcollector>
<!-- Proxmox Containers -->
<itopproxmoxcontainerproxmoxcollector>
<defaults>
<org_id>your_organization_name</org_id>
</defaults>
</itopproxmoxcontainerproxmoxcollector>
<!-- Proxmox Storage -->
<itopproxmoxstorageproxmoxcollector>
<defaults>
<org_id>your_organization_name</org_id>
</defaults>
</itopproxmoxstorageproxmoxcollector>
<!-- Servers -->
<itopserverproxmoxcollector>
<defaults>
<org_id>your_organization_name</org_id>
</defaults>
</itopserverproxmoxcollector>
<!-- Virtual machines -->
<itopvirtualmachineproxmoxcollector>
<defaults>
<org_id>your_organization_name</org_id>
</defaults>
</itopvirtualmachineproxmoxcollector>
我們先手動執行同步作業
sudo -u www-data /usr/bin/php
/var/www/html/itop/extensions/combodo-proxmox-data-collector/exec.php
--config_file=/etc/itop/params.proxmox.your_cluster_name.xml
完成資料同步後,就能在 iTop 的 CMDB 中,從 Proxmox 叢集點進個別節點。

以 Cluster1 為例,開啟其中一台節點的詳細頁面,可以看到主機名稱旁標示 Synchronized,並在 Properties 頁籤查看運作時間、管理 IP、CPU 型號、Proxmox VE 版本與核心資訊。
點開右上角的 Other tabs 還能查看與這台節點關聯的資源,iTop 列出了 3 筆儲存資源、4 顆 Proxmox 磁碟與 6 台虛擬機。日後規劃主機維護時,就可以先從 CMDB 找出這台節點關聯的虛擬機與儲存資源,作為評估影響範圍的起點。

確認同步沒有問題之後,記得將指令放入工作排程。
sudo crontab -u www-data -e
依照自己的環境調整頻率,例如每天上午八點執行。
00 08 * * * /usr/bin/php /var/www/html/itop/extensions/combodo-proxmox-data-collector/exec.php --config_file=/etc/itop/params.proxmox.your_cluster_name.xml > /tmp/data-collector-proxmox-your_cluster_name.log 2>&1
今天的分享就到這邊,感謝收看。
補充更新
建議 Data Collector 使用的權限應符合最小權限原則,接著我們介紹如何透過 API Tokens 進行認證。
回到 Datacenter 的 Permissions,選擇 API Tokens,點擊 Add 按鈕。
- Token ID:輸入 itop
- Privilege Separation:Enable
- Comment:Data Collector for Proxmox

建立後立即保存 Secret,它只會顯示一次。

回到 Datacenter 的 Permissions,點擊 Add 按鈕。
- Path:/
- API Token:root@pam!itop
- Role:PVEAuditor

編輯組態文件
sudo nano /etc/itop/params.proxmox.your_cluster_name.xml
<!-- Proxmox authentication: Use "ticket_cookie" or "api_tokens" -->
<proxmox_authentication_type>api_tokens</proxmox_authentication_type>
<proxmox_username>root@pam</proxmox_username>
<proxmox_password></proxmox_password>
<proxmox_token_id>itop</proxmox_token_id>
<proxmox_token_secret>c1a023db-b619-4985-824b-f95ab33a998c</proxmox_token_secret>
使用唯讀的 API Token 就能讀取 Proxmox 叢集內所有的節點與虛擬機器的資訊。即使 iTop 伺服器遭到入侵,攻擊者也無法透過這組 Token 修改 Proxmox 上的設定或資源。
