chore(connector): move vmware connector to centreon-plugins repo
This commit is contained in:
commit
c5b14a9357
|
@ -2,9 +2,15 @@ ARG REGISTRY_URL
|
|||
|
||||
FROM ${REGISTRY_URL}/almalinux:8
|
||||
|
||||
RUN <<EOF
|
||||
RUN bash -e <<EOF
|
||||
|
||||
dnf -y install git gettext rpm-build dos2unix python3 epel-release
|
||||
echo '[goreleaser]
|
||||
name=GoReleaser
|
||||
baseurl=https://repo.goreleaser.com/yum/
|
||||
enabled=1
|
||||
gpgcheck=0' | tee /etc/yum.repos.d/goreleaser.repo
|
||||
|
||||
dnf -y install git gettext rpm-build dos2unix python3 epel-release nfpm zstd
|
||||
dnf -y install perl-App-cpanminus perl-JSON
|
||||
cpanm App::FatPacker
|
||||
cpanm File::Copy::Recursive
|
||||
|
|
|
@ -2,9 +2,15 @@ ARG REGISTRY_URL
|
|||
|
||||
FROM ${REGISTRY_URL}/almalinux:9
|
||||
|
||||
RUN <<EOF
|
||||
RUN bash -e <<EOF
|
||||
|
||||
dnf -y install git gettext rpm-build dos2unix python3 epel-release
|
||||
echo '[goreleaser]
|
||||
name=GoReleaser
|
||||
baseurl=https://repo.goreleaser.com/yum/
|
||||
enabled=1
|
||||
gpgcheck=0' | tee /etc/yum.repos.d/goreleaser.repo
|
||||
|
||||
dnf -y install git gettext rpm-build dos2unix python3 epel-release nfpm zstd
|
||||
dnf -y install perl-App-cpanminus perl-JSON
|
||||
cpanm App::FatPacker
|
||||
cpanm File::Copy::Recursive
|
||||
|
|
|
@ -2,8 +2,10 @@ ARG REGISTRY_URL
|
|||
|
||||
FROM ${REGISTRY_URL}/debian:bullseye
|
||||
|
||||
ENV DEBIAN_FRONTEND noninteractive
|
||||
|
||||
# fix locale
|
||||
RUN <<EOF
|
||||
RUN bash -e <<EOF
|
||||
|
||||
apt-get update
|
||||
apt-get install -y locales
|
||||
|
@ -15,12 +17,14 @@ EOF
|
|||
|
||||
ENV LANG en_US.utf8
|
||||
|
||||
RUN <<EOF
|
||||
RUN bash -e <<EOF
|
||||
|
||||
apt-get update
|
||||
|
||||
apt-get install -y \
|
||||
dh-make \
|
||||
aptitude \
|
||||
ca-certificates \
|
||||
lintian \
|
||||
pbuilder \
|
||||
quilt \
|
||||
|
@ -34,7 +38,13 @@ apt-get install -y \
|
|||
libjson-perl \
|
||||
libapp-fatpacker-perl \
|
||||
libfile-copy-recursive-perl \
|
||||
jq
|
||||
jq \
|
||||
zstd
|
||||
|
||||
echo 'deb [trusted=yes] https://repo.goreleaser.com/apt/ /' | tee /etc/apt/sources.list.d/goreleaser.list
|
||||
apt-get update
|
||||
apt-get install -y nfpm
|
||||
|
||||
apt-get clean
|
||||
|
||||
EOF
|
||||
|
|
|
@ -2,9 +2,15 @@ ARG REGISTRY_URL
|
|||
|
||||
FROM ${REGISTRY_URL}/centos:7
|
||||
|
||||
RUN <<EOF
|
||||
RUN bash -e <<EOF
|
||||
|
||||
yum -y install git gettext rpm-build dos2unix python3 epel-release
|
||||
echo '[goreleaser]
|
||||
name=GoReleaser
|
||||
baseurl=https://repo.goreleaser.com/yum/
|
||||
enabled=1
|
||||
gpgcheck=0' | tee /etc/yum.repos.d/goreleaser.repo
|
||||
|
||||
yum -y install git gettext rpm-build dos2unix python3 epel-release nfpm zstd
|
||||
yum -y install perl-App-FatPacker perl-File-Copy-Recursive perl-JSON
|
||||
yum clean all
|
||||
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
name: connector-vmware
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
pull_request:
|
||||
paths:
|
||||
- 'connectors/vmware/src/**'
|
||||
- 'connectors/vmware/packaging/**'
|
||||
push:
|
||||
branches:
|
||||
- develop
|
||||
- master
|
||||
paths:
|
||||
- 'connectors/vmware/src/**'
|
||||
- 'connectors/vmware/packaging/**'
|
||||
tags:
|
||||
- centreon-connector-vmware-*
|
||||
|
||||
jobs:
|
||||
get-environment:
|
||||
uses: ./.github/workflows/get-environment.yml
|
||||
with:
|
||||
version_file: connectors/vmware/src/centreon/script/centreon_vmware.pm
|
||||
|
||||
package:
|
||||
needs:
|
||||
- get-environment
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- package_extension: rpm
|
||||
image: packaging-plugins-alma8
|
||||
distrib: el8
|
||||
- package_extension: rpm
|
||||
image: packaging-plugins-alma9
|
||||
distrib: el9
|
||||
- package_extension: deb
|
||||
image: packaging-plugins-bullseye
|
||||
distrib: bullseye
|
||||
name: package ${{ matrix.distrib }}
|
||||
|
||||
uses: ./.github/workflows/package.yml
|
||||
with:
|
||||
nfpm_file_pattern: "connectors/vmware/packaging/centreon-plugin-virtualization-vmware-daemon.yaml"
|
||||
distrib: ${{ matrix.distrib }}
|
||||
package_extension: ${{ matrix.package_extension }}
|
||||
image_name: ${{ matrix.image }}
|
||||
version: ${{ needs.get-environment.outputs.version }}
|
||||
release: ${{ needs.get-environment.outputs.release }}
|
||||
cache_key: ${{ github.sha }}-${{ github.run_id }}-${{ matrix.package_extension }}-${{ matrix.distrib }}
|
||||
secrets: inherit
|
||||
|
||||
deliver-rpm:
|
||||
needs:
|
||||
- get-environment
|
||||
- package
|
||||
if: ${{ contains(fromJson('["stable", "testing", "unstable"]'), needs.get-environment.outputs.stability) }}
|
||||
runs-on: [self-hosted, common]
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
distrib: [el8, el9]
|
||||
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Delivery
|
||||
uses: ./.github/actions/rpm-delivery
|
||||
with:
|
||||
module_name: connector-vmware
|
||||
distrib: ${{ matrix.distrib }}
|
||||
cache_key: ${{ github.sha }}-${{ github.run_id }}-rpm-${{ matrix.distrib }}
|
||||
update_repo_path: ${{ secrets.UPDATE_REPO_PATH }}
|
||||
cloudfront_id: ${{ secrets.CLOUDFRONT_ID }}
|
||||
yum_repo_address: ${{ secrets.YUM_REPO_ADDRESS }}
|
||||
yum_repo_key: ${{ secrets.YUM_REPO_KEY }}
|
||||
stability: ${{ needs.get-environment.outputs.stability }}
|
||||
artifactory_token: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }}
|
||||
|
||||
deliver-deb:
|
||||
needs:
|
||||
- get-environment
|
||||
- package
|
||||
if: ${{ contains(fromJson('["stable", "testing", "unstable"]'), needs.get-environment.outputs.stability) }}
|
||||
runs-on: [self-hosted, common]
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
distrib: [bullseye]
|
||||
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Delivery
|
||||
uses: ./.github/actions/deb-delivery
|
||||
with:
|
||||
distrib: ${{ matrix.distrib }}
|
||||
nexus_username: ${{ secrets.NEXUS_USERNAME }}
|
||||
nexus_password: ${{ secrets.NEXUS_PASSWORD }}
|
||||
cache_key: ${{ github.sha }}-${{ github.run_id }}-deb-${{ matrix.distrib }}
|
||||
stability: ${{ needs.get-environment.outputs.stability }}
|
||||
artifactory_token: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }}
|
|
@ -1,5 +1,9 @@
|
|||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
version_file:
|
||||
required: false
|
||||
type: string
|
||||
outputs:
|
||||
stability:
|
||||
description: "branch stability (stable, testing, unstable, canary)"
|
||||
|
@ -20,6 +24,9 @@ jobs:
|
|||
release: ${{ steps.get_environment.outputs.release }}
|
||||
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- id: get_environment
|
||||
run: |
|
||||
if [[ -z "$GITHUB_HEAD_REF" ]]; then
|
||||
|
@ -45,9 +52,13 @@ jobs:
|
|||
|
||||
echo "stability=$STABILITY" >> $GITHUB_OUTPUT
|
||||
|
||||
VERSION=`date '+%Y%m%d'`
|
||||
if [[ "${{ inputs.version_file }}" == "" ]]; then
|
||||
VERSION=$(date '+%Y%m%d')
|
||||
else
|
||||
VERSION=$(grep VERSION ${{ inputs.version_file }} | cut -d "'" -f 2)
|
||||
fi
|
||||
echo "version=$(echo $VERSION)" >> $GITHUB_OUTPUT
|
||||
|
||||
RELEASE=`date '+%H%M%S'`
|
||||
RELEASE=$(date '+%H%M%S')
|
||||
echo "release=$(echo $RELEASE)" >> $GITHUB_OUTPUT
|
||||
shell: bash
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
nfpm_file_pattern:
|
||||
type: string
|
||||
description: The pattern of the nfpm configuration file(s)
|
||||
required: true
|
||||
distrib:
|
||||
type: string
|
||||
description: The distrib
|
||||
required: true
|
||||
package_extension:
|
||||
type: string
|
||||
description: The package extension (deb or rpm)
|
||||
required: true
|
||||
image_name:
|
||||
type: string
|
||||
description: The image name
|
||||
required: true
|
||||
version:
|
||||
type: string
|
||||
description: The package version
|
||||
required: false
|
||||
release:
|
||||
type: string
|
||||
description: The release number
|
||||
required: false
|
||||
source_cache_key:
|
||||
type: string
|
||||
description: The source files cache key
|
||||
required: false
|
||||
source_cache_path:
|
||||
type: string
|
||||
description: The source files path
|
||||
required: false
|
||||
cache_key:
|
||||
type: string
|
||||
description: The package files cache key
|
||||
required: true
|
||||
|
||||
jobs:
|
||||
package:
|
||||
runs-on: ubuntu-22.04
|
||||
container:
|
||||
image: ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }}/${{ inputs.image_name }}
|
||||
credentials:
|
||||
username: ${{ secrets.DOCKER_REGISTRY_ID }}
|
||||
password: ${{ secrets.DOCKER_REGISTRY_PASSWD }}
|
||||
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Import gpg key
|
||||
env:
|
||||
RPM_GPG_SIGNING_KEY: ${{ secrets.RPM_GPG_SIGNING_KEY }}
|
||||
run: echo -n "$RPM_GPG_SIGNING_KEY" > key.gpg
|
||||
shell: bash
|
||||
|
||||
- if: ${{ inputs.source_cache_key != '' && inputs.source_cache_path != '' }}
|
||||
name: Import source files
|
||||
uses: actions/cache/restore@v3
|
||||
with:
|
||||
path: ${{ inputs.source_cache_path }}
|
||||
key: ${{ inputs.source_cache_key }}
|
||||
fail-on-cache-miss: true
|
||||
|
||||
- name: Build ${{ inputs.package_extension }} files
|
||||
env:
|
||||
RPM_GPG_SIGNING_KEY_ID: ${{ secrets.RPM_GPG_SIGNING_KEY_ID }}
|
||||
RPM_GPG_SIGNING_PASSPHRASE: ${{ secrets.RPM_GPG_SIGNING_PASSPHRASE }}
|
||||
run: |
|
||||
export VERSION="${{ inputs.version }}"
|
||||
export RELEASE="${{ inputs.release }}"
|
||||
|
||||
if [ "${{ inputs.package_extension }}" = "rpm" ]; then
|
||||
export DIST=".${{ inputs.distrib }}"
|
||||
export APACHE_USER="apache"
|
||||
export APACHE_GROUP="apache"
|
||||
else
|
||||
export DIST=""
|
||||
export APACHE_USER="www-data"
|
||||
export APACHE_GROUP="www-data"
|
||||
fi
|
||||
|
||||
export PERL_SITELIB="$(eval "$(perl -V:installsitelib)"; echo $installsitelib)"
|
||||
export PERL_VENDORLIB="$(eval "$(perl -V:installvendorlib)"; echo $installvendorlib)"
|
||||
|
||||
export RPM_SIGNING_KEY_FILE="$(pwd)/key.gpg"
|
||||
export RPM_SIGNING_KEY_ID="$RPM_GPG_SIGNING_KEY_ID"
|
||||
export NFPM_RPM_PASSPHRASE="$RPM_GPG_SIGNING_PASSPHRASE"
|
||||
|
||||
for FILE in ${{ inputs.nfpm_file_pattern }}; do
|
||||
DIRNAME=$(dirname $FILE)
|
||||
BASENAME=$(basename $FILE)
|
||||
cd $DIRNAME
|
||||
sed -i \
|
||||
"s/@COMMIT_HASH@/${{ github.sha }}/g; s#@PERL_SITELIB@#${PERL_SITELIB}#g; s#@PERL_VENDORLIB@#${PERL_VENDORLIB}#g" \
|
||||
$BASENAME
|
||||
nfpm package --config $BASENAME --packager ${{ inputs.package_extension }}
|
||||
cd -
|
||||
mv $DIRNAME/*.${{ inputs.package_extension }} ./
|
||||
done
|
||||
shell: bash
|
||||
|
||||
- name: Upload package artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: packages-${{ inputs.distrib }}
|
||||
path: ./*.${{ inputs.package_extension }}
|
||||
retention-days: 1
|
||||
|
||||
- name: Cache packages
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ./*.${{ inputs.package_extension }}
|
||||
key: ${{ inputs.cache_key }}
|
|
@ -0,0 +1,128 @@
|
|||
name: perl-vmware-vsphere
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
pull_request:
|
||||
paths:
|
||||
- 'dependencies/perl-vmware-vsphere/**'
|
||||
push:
|
||||
branches:
|
||||
- develop
|
||||
- master
|
||||
paths:
|
||||
- 'dependencies/perl-vmware-vsphere/**'
|
||||
tags:
|
||||
- perl-vmware-vsphere-*
|
||||
|
||||
jobs:
|
||||
get-environment:
|
||||
uses: ./.github/workflows/get-environment.yml
|
||||
with:
|
||||
version_file: connectors/vmware/src/centreon/script/centreon_vmware.pm
|
||||
|
||||
get-sources:
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- name: Download vsphere cli sources
|
||||
run: |
|
||||
wget https://gitlab.labexposed.com/centreon-lab/perl-VMware-vSphere/-/raw/master/storage/VMware-vSphere-Perl-SDK-7.0.0-17698549.x86_64.tar.gz
|
||||
tar zxf VMware-vSphere-Perl-SDK-7.0.0-17698549.x86_64.tar.gz
|
||||
shell: bash
|
||||
|
||||
- name: Build vsphere cli sources
|
||||
run: |
|
||||
cd vmware-vsphere-cli-distrib
|
||||
perl Makefile.PL
|
||||
sudo make pure_install
|
||||
shell: bash
|
||||
|
||||
- name: Cache vsphere cli sources
|
||||
uses: actions/cache/save@v3
|
||||
with:
|
||||
path: vmware-vsphere-cli-distrib
|
||||
key: ${{ github.sha }}-${{ github.run_id }}-sources-perl-vmware-vsphere
|
||||
|
||||
package:
|
||||
needs:
|
||||
- get-sources
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- package_extension: rpm
|
||||
image: packaging-plugins-alma8
|
||||
distrib: el8
|
||||
- package_extension: rpm
|
||||
image: packaging-plugins-alma9
|
||||
distrib: el9
|
||||
- package_extension: deb
|
||||
image: packaging-plugins-bullseye
|
||||
distrib: bullseye
|
||||
name: package ${{ matrix.distrib }}
|
||||
|
||||
uses: ./.github/workflows/package.yml
|
||||
with:
|
||||
nfpm_file_pattern: "dependencies/perl-vmware-vsphere/packaging/perl-vmware-vsphere.yaml"
|
||||
distrib: ${{ matrix.distrib }}
|
||||
package_extension: ${{ matrix.package_extension }}
|
||||
image_name: ${{ matrix.image }}
|
||||
source_cache_key: ${{ github.sha }}-${{ github.run_id }}-sources-perl-vmware-vsphere
|
||||
source_cache_path: vmware-vsphere-cli-distrib
|
||||
cache_key: ${{ github.sha }}-${{ github.run_id }}-${{ matrix.package_extension }}-${{ matrix.distrib }}
|
||||
secrets: inherit
|
||||
|
||||
deliver-rpm:
|
||||
needs:
|
||||
- get-environment
|
||||
- package
|
||||
if: ${{ contains(fromJson('["stable", "testing", "unstable"]'), needs.get-environment.outputs.stability) }}
|
||||
runs-on: [self-hosted, common]
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
distrib: [el8, el9]
|
||||
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Delivery
|
||||
uses: ./.github/actions/rpm-delivery
|
||||
with:
|
||||
module_name: connector-vmware
|
||||
distrib: ${{ matrix.distrib }}
|
||||
cache_key: ${{ github.sha }}-${{ github.run_id }}-rpm-${{ matrix.distrib }}
|
||||
update_repo_path: ${{ secrets.UPDATE_REPO_PATH }}
|
||||
cloudfront_id: ${{ secrets.CLOUDFRONT_ID }}
|
||||
yum_repo_address: ${{ secrets.YUM_REPO_ADDRESS }}
|
||||
yum_repo_key: ${{ secrets.YUM_REPO_KEY }}
|
||||
stability: ${{ needs.get-environment.outputs.stability }}
|
||||
artifactory_token: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }}
|
||||
|
||||
deliver-deb:
|
||||
needs:
|
||||
- get-environment
|
||||
- package
|
||||
if: ${{ contains(fromJson('["stable", "testing", "unstable"]'), needs.get-environment.outputs.stability) }}
|
||||
runs-on: [self-hosted, common]
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
distrib: [bullseye]
|
||||
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Delivery
|
||||
uses: ./.github/actions/deb-delivery
|
||||
with:
|
||||
distrib: ${{ matrix.distrib }}
|
||||
nexus_username: ${{ secrets.NEXUS_USERNAME }}
|
||||
nexus_password: ${{ secrets.NEXUS_PASSWORD }}
|
||||
cache_key: ${{ github.sha }}-${{ github.run_id }}-deb-${{ matrix.distrib }}
|
||||
stability: ${{ needs.get-environment.outputs.stability }}
|
||||
artifactory_token: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }}
|
|
@ -0,0 +1,78 @@
|
|||
# centreon-vmware
|
||||
|
||||
"centreon-vmware" is a free and open source project. The project can be used with Centreon and all monitoring softwares compatible with Nagios plugins.
|
||||
It's a Perl daemon in charged to get back VMWare indicators. This program uses the SDK Perl provided by VMWare.
|
||||
|
||||
The connector could get following indicators:
|
||||
* For ESX Server:
|
||||
* Current alarms
|
||||
* CPU usage
|
||||
* Memory usage
|
||||
* Swap usage
|
||||
* Interface trafics
|
||||
* Count VMs
|
||||
* Health status
|
||||
* Global status
|
||||
* Uptime
|
||||
* For Virtual Machines:
|
||||
* CPU usage
|
||||
* Memory usage
|
||||
* Swap usage
|
||||
* IOPs on datastores
|
||||
* Limits configured (CPU, memory and disks)
|
||||
* Snapshot age and consolidation
|
||||
* Thinprovisioning configuration
|
||||
* VMTools state
|
||||
* For Datastores:
|
||||
* Usage
|
||||
* IOPs
|
||||
* Usage in bytes/s
|
||||
* Snapshost sizes
|
||||
* For Cluster:
|
||||
* Operations on virtual machines (Clone, VMotion,...)
|
||||
* For Datacenter:
|
||||
* Current alarms
|
||||
|
||||
You can check one or X entities for each checks. Moreover, you can also "scope" it. It means: i can check the virtual machines of a datacenter(s) and/or a cluster(s).
|
||||
|
||||
Please follow the documentation for the installation: https://github.com/centreon/centreon-vmware/blob/master/doc/en/installation/index.rst
|
||||
|
||||
## Examples
|
||||
|
||||
Check vmtools states of virtual machines (with name matching the regexp 'prd'):
|
||||
|
||||
$ perl centreon_plugins.pl --plugin=apps::vmware::connector::plugin --connector-hostname=127.0.0.1 --container=default --verbose --mode=tools-vm --display-description --vm-hostname='prd' --filter
|
||||
WARNING: 1 VM with VMTools not installed |
|
||||
vmtools not installed:
|
||||
prd-Reporting - 10.0.0.1 [description xxxx]
|
||||
|
||||
Check datastore IOPs of virtual machines (with name matching the regexp 'centreon-central-1|Formation'):
|
||||
|
||||
$ perl centreon_plugins.pl --plugin=apps::vmware::connector::plugin --connector-hostname=127.0.0.1 --container=default --verbose --mode=datastore-vm --vm-hostname='woot|test-migration' --filter
|
||||
OK: All virtual machines are ok | 'max_total_latency_test-migration'=2.00ms;;;0; 'riops_test-migration_INTEGRATION'=0.41iops;;;0; 'wiops_test-migration_INTEGRATION'=4.84iops;;;0;4.84 'riops_test-migration_ISOs'=0.00iops;;;0; 'wiops_test-migration_ISOs'=0.00iops;;;0;0.00 'max_total_latency_woot'=23.00ms;;;0; 'riops_woot'=0.02iops;;;0; 'wiops_woot'=0.67iops;;;0;0.67
|
||||
checking virtual machine 'test-migration'
|
||||
[connection state connected][power state poweredOn]
|
||||
max total latency is 2.00 ms
|
||||
datastore 'INTEGRATION' 0.41 read iops, 4.84 write iops
|
||||
datastore 'ISOs' 0.00 read iops, 0.00 write iops
|
||||
checking virtual machine 'woot'
|
||||
[connection state connected][power state poweredOn]
|
||||
max total latency is 23.00 ms
|
||||
datastore 'DSI' 0.02 read iops, 0.67 write iops
|
||||
|
||||
Check the health of ESX Servers:
|
||||
|
||||
$ perl centreon_plugins.pl --plugin=apps::vmware::connector::plugin --connector-hostname=127.0.0.1 --container=default --verbose --mode=health-host --esx-hostname='.*' --filter --disconnect-status='ok'
|
||||
OK: 0 total health issue(s) found - All ESX hosts are ok | 'total_problems'=0;;;0;1034 'problems_srvi-clus-esx-n1.int.centreon.com'=0;;;0;315 'problems_yellow_srvi-clus-esx-n1.int.centreon.com'=0;;;0;315 'problems_red_srvi-clus-esx-n1.int.centreon.com'=0;;;0;315 'problems_srvi-clus-esx-n2.int.centreon.com'=0;;;0;315 'problems_yellow_srvi-clus-esx-n2.int.centreon.com'=0;;;0;315 'problems_red_srvi-clus-esx-n2.int.centreon.com'=0;;;0;315 'problems_srvi-clus-esx-n3.int.centreon.com'=0;;;0;202 'problems_yellow_srvi-clus-esx-n3.int.centreon.com'=0;;;0;202 'problems_red_srvi-clus-esx-n3.int.centreon.com'=0;;;0;202 'problems_srvi-clus-esx-n4.int.centreon.com'=0;;;0;202 'problems_yellow_srvi-clus-esx-n4.int.centreon.com'=0;;;0;202 'problems_red_srvi-clus-esx-n4.int.centreon.com'=0;;;0;202
|
||||
checking host 'srvi-clus-esx-n1.int.centreon.com'
|
||||
status connected
|
||||
315 health checks are green, 0 total health issue(s) found, 0 yellow health issue(s) found, 0 red health issue(s) found
|
||||
checking host 'srvi-clus-esx-n2.int.centreon.com'
|
||||
status connected
|
||||
315 health checks are green, 0 total health issue(s) found, 0 yellow health issue(s) found, 0 red health issue(s) found
|
||||
checking host 'srvi-clus-esx-n3.int.centreon.com'
|
||||
status connected
|
||||
202 health checks are green, 0 total health issue(s) found, 0 yellow health issue(s) found, 0 red health issue(s) found
|
||||
checking host 'srvi-clus-esx-n4.int.centreon.com'
|
||||
status connected
|
||||
202 health checks are green, 0 total health issue(s) found, 0 yellow health issue(s) found, 0 red health issue(s) found
|
|
@ -0,0 +1,95 @@
|
|||
2022-08-09 Quentin Garnier <qgarnier@centreon.com> - 3.2.5
|
||||
* Enhancement: add tags in discovery
|
||||
|
||||
2022-04-14 Quentin Garnier <qgarnier@centreon.com> - 3.2.4
|
||||
* Fix: custom attributes retrieved for vcenter only
|
||||
|
||||
2022-04-14 Quentin Garnier <qgarnier@centreon.com> - 3.2.3
|
||||
* Enhancement: add custom attributes in discovery
|
||||
|
||||
2021-12-21 Quentin Garnier <qgarnier@centreon.com> - 3.2.2
|
||||
* Enhancement: add 'storage-host'
|
||||
* Enhancement: add 'cpu-cluster' (issue #90)
|
||||
* Enhancement: add 'licenses'
|
||||
* Enhancement: add refresh capability for datastore-usage (issue #96)
|
||||
* Enhancement: container label in configuration is case-insensitive (issue #83)
|
||||
* Enhancement: add capability to use empty-continue option (issue #77)
|
||||
|
||||
2020-11-03 Quentin Garnier <qgarnier@centreon.com> - 3.2.1
|
||||
* Fix: daemon cannot start (issue #92)
|
||||
|
||||
2020-11-02 Quentin Garnier <qgarnier@centreon.com> - 3.2.0
|
||||
* Enhancement: add 'net-vm'
|
||||
* Enhancement: add 'hosts' attached to datastores for 'datastore-usage'
|
||||
* Fix: remove vm without uuid for 'discovery'
|
||||
|
||||
2020-04-06 Quentin Garnier <qgarnier@centreon.com> - 3.1.2
|
||||
* Enhancement: add drs and das config enable 'cluster-status'
|
||||
* Enhancement: remove carriage return from vm annotation in discovery
|
||||
* Fix: remove errors in logs 'net-host'
|
||||
|
||||
2020-02-20 Quentin Garnier <qgarnier@centreon.com> - 3.1.1
|
||||
* Fix: discovery folders management
|
||||
* Fix: no virtual machines running for 'datastore-vm'
|
||||
* Fix: undefined error for 'thinprovisioning-vm'
|
||||
|
||||
2019-08-27 Quentin Garnier <qgarnier@centreon.com> - 3.1.0
|
||||
* Enhancement: add 'status-cluster' and 'vsan-cluster-usage'
|
||||
* Fix: Can listen only on localhost (issue #81)
|
||||
* Fix: Can configure ipc_file location
|
||||
|
||||
2019-07-04 Colin Gagnaire <cgagnaire@centreon.com> - 3.0.3
|
||||
* Fix: Datacenter with no cluster causes discovery to crash
|
||||
* Fix: Cluster with no ESX causes discovery to crash
|
||||
|
||||
2019-06-06 Colin Gagnaire <cgagnaire@centreon.com> - 3.0.2
|
||||
* Fix: ESX with no VMs causes VM discovery to crash
|
||||
* Fix: VM with no folder causes VM discovery to crash
|
||||
|
||||
2019-04-12 Colin Gagnaire <cgagnaire@centreon.com> - 3.0.1
|
||||
* Enhancement: add resource type filter option for discovery
|
||||
* Enhancement: add uuid and folder to vm discovery
|
||||
* Enhancement: add uuid filter in vm modes
|
||||
|
||||
2019-01-06 Quentin Garnier <qgarnier@centreon.com> - 3.0.0
|
||||
* Enhancement: checking intelligence is moved in centreon-plugins
|
||||
* Enhancement: autonomous daemon - remove dependency with centreon-plugins-base and perl centreon base library
|
||||
* Enhancement: update debian doc
|
||||
* Enhancement: Can filter on guest os virtual machine (option --filter-os in centreon-plugins)
|
||||
* Enhancement: Can choose case insensitive searching (option --case-insensitive in centreon-plugins)
|
||||
|
||||
2017-05-31 Quentin Garnier <qgarnier@centreon.com> - 2.4.0
|
||||
* Enhance: Use ZMQ4 library
|
||||
|
||||
2017-05-16 Quentin Garnier <qgarnier@centreon.com> - 2.3.2
|
||||
* Fix: miscalcultion in datastores-snapshot (issue #39)
|
||||
* Fix: problem with --tools-notinstalled-status option (issue #38)
|
||||
* Fix: host memory state problem (issue #40)
|
||||
|
||||
2016-11-17 Quentin Garnier <qgarnier@centreon.com> - 2.3.1
|
||||
* Enhance: Add an option to not check memory ESX state
|
||||
|
||||
2016-08-04 Quentin Garnier <qgarnier@centreon.com> - 2.3.0
|
||||
* Enhance: Add a mode to check connected device (issue #20)
|
||||
* Enhance: Option to use case-insensitive search (issue #14)
|
||||
* Enhance: Add memory state for ESX check
|
||||
* Fix: Hardening connector about blocked childs
|
||||
|
||||
2016-05-26 Quentin Garnier <qgarnier@centreon.com> - 2.2.1
|
||||
* Enhance: Better management of ESX/VCenter disconnect
|
||||
* Enhance: Add counter 'max-total-latency' for mode 'datastore-vm'
|
||||
|
||||
2016-01-15 Quentin Garnier <qgarnier@centreon.com> - 2.2.0
|
||||
* Enhance: Can check ESX time offset (issue #9)
|
||||
* Fix: displaying object name in alarm-* modes (issue #12)
|
||||
|
||||
2015-12-03 Quentin Garnier <qgarnier@centreon.com> - 2.1.0
|
||||
* Enhance: Add a command to monitor ESX services (issue #3)
|
||||
* Enhance: Can choose the sampling period (issue #1)
|
||||
* Enhance: Display ESX version in command 'getmap' (issue #2)
|
||||
* Fix: Hardening connector (issue #5)
|
||||
* Fix: error for 'alarm-*' commands (issue #4)
|
||||
* Fix: counter 'active' for command 'memory-vm' (issue #6)
|
||||
|
||||
2015-09-23 Quentin Garnier <qgarnier@centreon.com> - 2.0.0
|
||||
* initial release
|
|
@ -0,0 +1,177 @@
|
|||
# Makefile for Sphinx documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line.
|
||||
SPHINXOPTS =
|
||||
SPHINXBUILD = sphinx-build
|
||||
PAPER =
|
||||
BUILDDIR = _build
|
||||
|
||||
# User-friendly check for sphinx-build
|
||||
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
|
||||
$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
|
||||
endif
|
||||
|
||||
# Internal variables.
|
||||
PAPEROPT_a4 = -D latex_paper_size=a4
|
||||
PAPEROPT_letter = -D latex_paper_size=letter
|
||||
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
|
||||
# the i18n builder cannot share the environment and doctrees with the others
|
||||
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
|
||||
|
||||
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
|
||||
|
||||
help:
|
||||
@echo "Please use \`make <target>' where <target> is one of"
|
||||
@echo " html to make standalone HTML files"
|
||||
@echo " dirhtml to make HTML files named index.html in directories"
|
||||
@echo " singlehtml to make a single large HTML file"
|
||||
@echo " pickle to make pickle files"
|
||||
@echo " json to make JSON files"
|
||||
@echo " htmlhelp to make HTML files and a HTML help project"
|
||||
@echo " qthelp to make HTML files and a qthelp project"
|
||||
@echo " devhelp to make HTML files and a Devhelp project"
|
||||
@echo " epub to make an epub"
|
||||
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
|
||||
@echo " latexpdf to make LaTeX files and run them through pdflatex"
|
||||
@echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
|
||||
@echo " text to make text files"
|
||||
@echo " man to make manual pages"
|
||||
@echo " texinfo to make Texinfo files"
|
||||
@echo " info to make Texinfo files and run them through makeinfo"
|
||||
@echo " gettext to make PO message catalogs"
|
||||
@echo " changes to make an overview of all changed/added/deprecated items"
|
||||
@echo " xml to make Docutils-native XML files"
|
||||
@echo " pseudoxml to make pseudoxml-XML files for display purposes"
|
||||
@echo " linkcheck to check all external links for integrity"
|
||||
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILDDIR)/*
|
||||
|
||||
html:
|
||||
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
|
||||
|
||||
dirhtml:
|
||||
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
|
||||
|
||||
singlehtml:
|
||||
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
|
||||
@echo
|
||||
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
|
||||
|
||||
pickle:
|
||||
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
|
||||
@echo
|
||||
@echo "Build finished; now you can process the pickle files."
|
||||
|
||||
json:
|
||||
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
|
||||
@echo
|
||||
@echo "Build finished; now you can process the JSON files."
|
||||
|
||||
htmlhelp:
|
||||
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run HTML Help Workshop with the" \
|
||||
".hhp project file in $(BUILDDIR)/htmlhelp."
|
||||
|
||||
qthelp:
|
||||
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
|
||||
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
|
||||
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/CentreonESXD.qhcp"
|
||||
@echo "To view the help file:"
|
||||
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/CentreonESXD.qhc"
|
||||
|
||||
devhelp:
|
||||
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
|
||||
@echo
|
||||
@echo "Build finished."
|
||||
@echo "To view the help file:"
|
||||
@echo "# mkdir -p $$HOME/.local/share/devhelp/CentreonESXD"
|
||||
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/CentreonESXD"
|
||||
@echo "# devhelp"
|
||||
|
||||
epub:
|
||||
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
|
||||
@echo
|
||||
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
|
||||
|
||||
latex:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo
|
||||
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
|
||||
@echo "Run \`make' in that directory to run these through (pdf)latex" \
|
||||
"(use \`make latexpdf' here to do that automatically)."
|
||||
|
||||
latexpdf:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo "Running LaTeX files through pdflatex..."
|
||||
$(MAKE) -C $(BUILDDIR)/latex all-pdf
|
||||
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
|
||||
|
||||
latexpdfja:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo "Running LaTeX files through platex and dvipdfmx..."
|
||||
$(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
|
||||
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
|
||||
|
||||
text:
|
||||
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
|
||||
@echo
|
||||
@echo "Build finished. The text files are in $(BUILDDIR)/text."
|
||||
|
||||
man:
|
||||
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
|
||||
@echo
|
||||
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
|
||||
|
||||
texinfo:
|
||||
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
|
||||
@echo
|
||||
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
|
||||
@echo "Run \`make' in that directory to run these through makeinfo" \
|
||||
"(use \`make info' here to do that automatically)."
|
||||
|
||||
info:
|
||||
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
|
||||
@echo "Running Texinfo files through makeinfo..."
|
||||
make -C $(BUILDDIR)/texinfo info
|
||||
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
|
||||
|
||||
gettext:
|
||||
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
|
||||
@echo
|
||||
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
|
||||
|
||||
changes:
|
||||
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
|
||||
@echo
|
||||
@echo "The overview file is in $(BUILDDIR)/changes."
|
||||
|
||||
linkcheck:
|
||||
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
|
||||
@echo
|
||||
@echo "Link check complete; look for any errors in the above output " \
|
||||
"or in $(BUILDDIR)/linkcheck/output.txt."
|
||||
|
||||
doctest:
|
||||
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
|
||||
@echo "Testing of doctests in the sources finished, look at the " \
|
||||
"results in $(BUILDDIR)/doctest/output.txt."
|
||||
|
||||
xml:
|
||||
$(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
|
||||
@echo
|
||||
@echo "Build finished. The XML files are in $(BUILDDIR)/xml."
|
||||
|
||||
pseudoxml:
|
||||
$(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
|
||||
@echo
|
||||
@echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
|
|
@ -0,0 +1,248 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Centreon ESXD documentation build configuration file, created by
|
||||
# sphinx-quickstart on Mon Apr 22 11:17:38 2013.
|
||||
#
|
||||
# This file is execfile()d with the current directory set to its containing dir.
|
||||
#
|
||||
# Note that not all possible configuration values are present in this
|
||||
# autogenerated file.
|
||||
#
|
||||
# All configuration values have a default; values that are commented out
|
||||
# serve to show the default.
|
||||
|
||||
import sys, os
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
#sys.path.insert(0, os.path.abspath('.'))
|
||||
|
||||
# -- General configuration -----------------------------------------------------
|
||||
|
||||
# If your documentation needs a minimal Sphinx version, state it here.
|
||||
#needs_sphinx = '1.0'
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be extensions
|
||||
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
|
||||
extensions = []
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
|
||||
# The suffix of source filenames.
|
||||
source_suffix = '.rst'
|
||||
|
||||
# The encoding of source files.
|
||||
#source_encoding = 'utf-8-sig'
|
||||
|
||||
# The master toctree document.
|
||||
master_doc = 'index'
|
||||
|
||||
# General information about the project.
|
||||
project = u'Centreon VMWare'
|
||||
copyright = u'2015, Centreon'
|
||||
|
||||
# The version info for the project you're documenting, acts as replacement for
|
||||
# |version| and |release|, also used in various other places throughout the
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = '2.0'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = '2.0.0'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
#language = None
|
||||
|
||||
# There are two options for replacing |today|: either, you set today to some
|
||||
# non-false value, then it is used:
|
||||
#today = ''
|
||||
# Else, today_fmt is used as the format for a strftime call.
|
||||
#today_fmt = '%B %d, %Y'
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
exclude_patterns = ['_build']
|
||||
|
||||
# The reST default role (used for this markup: `text`) to use for all documents.
|
||||
#default_role = None
|
||||
|
||||
# If true, '()' will be appended to :func: etc. cross-reference text.
|
||||
#add_function_parentheses = True
|
||||
|
||||
# If true, the current module name will be prepended to all description
|
||||
# unit titles (such as .. function::).
|
||||
#add_module_names = True
|
||||
|
||||
# If true, sectionauthor and moduleauthor directives will be shown in the
|
||||
# output. They are ignored by default.
|
||||
#show_authors = False
|
||||
|
||||
# The name of the Pygments (syntax highlighting) style to use.
|
||||
pygments_style = 'sphinx'
|
||||
|
||||
# A list of ignored prefixes for module index sorting.
|
||||
#modindex_common_prefix = []
|
||||
|
||||
# If true, keep warnings as "system message" paragraphs in the built documents.
|
||||
#keep_warnings = False
|
||||
|
||||
|
||||
# -- Options for HTML output ---------------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
html_theme = 'default'
|
||||
|
||||
# Theme options are theme-specific and customize the look and feel of a theme
|
||||
# further. For a list of options available for each theme, see the
|
||||
# documentation.
|
||||
#html_theme_options = {}
|
||||
|
||||
# Add any paths that contain custom themes here, relative to this directory.
|
||||
#html_theme_path = []
|
||||
|
||||
# The name for this set of Sphinx documents. If None, it defaults to
|
||||
# "<project> v<release> documentation".
|
||||
#html_title = None
|
||||
|
||||
# A shorter title for the navigation bar. Default is the same as html_title.
|
||||
#html_short_title = None
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top
|
||||
# of the sidebar.
|
||||
#html_logo = None
|
||||
|
||||
# The name of an image file (within the static path) to use as favicon of the
|
||||
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
|
||||
# pixels large.
|
||||
#html_favicon = None
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ['_static']
|
||||
|
||||
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
|
||||
# using the given strftime format.
|
||||
#html_last_updated_fmt = '%b %d, %Y'
|
||||
|
||||
# If true, SmartyPants will be used to convert quotes and dashes to
|
||||
# typographically correct entities.
|
||||
#html_use_smartypants = True
|
||||
|
||||
# Custom sidebar templates, maps document names to template names.
|
||||
#html_sidebars = {}
|
||||
|
||||
# Additional templates that should be rendered to pages, maps page names to
|
||||
# template names.
|
||||
#html_additional_pages = {}
|
||||
|
||||
# If false, no module index is generated.
|
||||
#html_domain_indices = True
|
||||
|
||||
# If false, no index is generated.
|
||||
#html_use_index = True
|
||||
|
||||
# If true, the index is split into individual pages for each letter.
|
||||
#html_split_index = False
|
||||
|
||||
# If true, links to the reST sources are added to the pages.
|
||||
#html_show_sourcelink = True
|
||||
|
||||
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
|
||||
#html_show_sphinx = True
|
||||
|
||||
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
|
||||
#html_show_copyright = True
|
||||
|
||||
# If true, an OpenSearch description file will be output, and all pages will
|
||||
# contain a <link> tag referring to it. The value of this option must be the
|
||||
# base URL from which the finished HTML is served.
|
||||
#html_use_opensearch = ''
|
||||
|
||||
# This is the file name suffix for HTML files (e.g. ".xhtml").
|
||||
#html_file_suffix = None
|
||||
|
||||
# Output file base name for HTML help builder.
|
||||
htmlhelp_basename = 'CentreonESXDdoc'
|
||||
|
||||
|
||||
# -- Options for LaTeX output --------------------------------------------------
|
||||
|
||||
latex_elements = {
|
||||
# The paper size ('letterpaper' or 'a4paper').
|
||||
#'papersize': 'letterpaper',
|
||||
|
||||
# The font size ('10pt', '11pt' or '12pt').
|
||||
#'pointsize': '10pt',
|
||||
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
#'preamble': '',
|
||||
}
|
||||
|
||||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
# (source start file, target name, title, author, documentclass [howto/manual]).
|
||||
latex_documents = [
|
||||
('index', 'CentreonESXD.tex', u'Centreon ESXD Documentation',
|
||||
u'Merethis', 'manual'),
|
||||
]
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top of
|
||||
# the title page.
|
||||
#latex_logo = None
|
||||
|
||||
# For "manual" documents, if this is true, then toplevel headings are parts,
|
||||
# not chapters.
|
||||
#latex_use_parts = False
|
||||
|
||||
# If true, show page references after internal links.
|
||||
#latex_show_pagerefs = False
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
#latex_show_urls = False
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
#latex_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
#latex_domain_indices = True
|
||||
|
||||
|
||||
# -- Options for manual page output --------------------------------------------
|
||||
|
||||
# One entry per manual page. List of tuples
|
||||
# (source start file, name, description, authors, manual section).
|
||||
man_pages = [
|
||||
('index', 'centreonesxd', u'Centreon ESXD Documentation',
|
||||
[u'Merethis'], 1)
|
||||
]
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
#man_show_urls = False
|
||||
|
||||
|
||||
# -- Options for Texinfo output ------------------------------------------------
|
||||
|
||||
# Grouping the document tree into Texinfo files. List of tuples
|
||||
# (source start file, target name, title, author,
|
||||
# dir menu entry, description, category)
|
||||
texinfo_documents = [
|
||||
('index', 'CentreonESXD', u'Centreon ESXD Documentation',
|
||||
u'Merethis', 'CentreonESXD', 'One line description of project.',
|
||||
'Miscellaneous'),
|
||||
]
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
#texinfo_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
#texinfo_domain_indices = True
|
||||
|
||||
# How to display URL addresses: 'footnote', 'no', or 'inline'.
|
||||
#texinfo_show_urls = 'footnote'
|
||||
|
||||
# If true, do not generate a @detailmenu in the "Top" node's menu.
|
||||
#texinfo_no_detailmenu = False
|
|
@ -0,0 +1,120 @@
|
|||
============
|
||||
Exploitation
|
||||
============
|
||||
|
||||
Generals Principles
|
||||
-------------------
|
||||
|
||||
Centreon-vmware is a Perl program in charged to get back VMWare indicators. This program uses the SDK Perl provided by VMWare in order to connect and get back the informations of one (or more) Virtual Center. To do this, it makes a TCP connection with the VirtualCenter.
|
||||
|
||||
By default "centreon-vmware" starts at least two processes (named "handle-client" and "handle-vsphere-xxxx") :
|
||||
|
||||
*« handle-client »*:
|
||||
*Process waiting for requests of clients.*
|
||||
|
||||
Steps of operation :
|
||||
|
||||
- A client connects.
|
||||
- The client ask an monitoring indicator on a VirtualCenter.
|
||||
- The process "handle-client" sends the request to process "handle-vsphere-xxxx".
|
||||
- A response is sent by "handle-vsphere-xxxx" to "handle-client".
|
||||
- The process "handle-client" sends the response to the client.
|
||||
|
||||
*« handle-vsphere-xxxx »*:
|
||||
*Process responsible to connect and to keep opened a session with the VirtualCenter. To ensure quality performance, a cache of datas description is created.*
|
||||
|
||||
Then, this process gets back the VMWare indicators creating a subprocess per request.
|
||||
|
||||
Centreon-vmware necessitates the utilization of one (or more) VirtualCenter (or ESX).
|
||||
This is a example of a distributed architecture :
|
||||
|
||||
.. image:: ../images/archi.png
|
||||
|
||||
Operating mode
|
||||
--------------
|
||||
|
||||
The "centreon-vmware" program only works in "daemon" mode (a client is needed).
|
||||
|
||||
Connector configuration
|
||||
-----------------------
|
||||
|
||||
The « centreon-vmware » daemon is configured with the « centreon_vmware.pm » configuration file:
|
||||
::
|
||||
|
||||
%centreon_vmware_config = (
|
||||
vsphere_server => {
|
||||
'default' => {'url' => 'https://vcenter/sdk',
|
||||
'username' => 'test@test.fr',
|
||||
'password' => 'xxxx'},
|
||||
}
|
||||
);
|
||||
|
||||
« vsphere_server » attribute configures VirtualCenter access.
|
||||
In case you have many VirtualCenters, the configuration is (note the use of "," as a separator):
|
||||
::
|
||||
|
||||
%centreon_vmware_config = (
|
||||
vsphere_server => {
|
||||
'default' => {'url' => 'https://vcenter/sdk',
|
||||
'username' => 'test@test.fr',
|
||||
'password' => 'xxxx'},
|
||||
'other' => {'url' => 'https://other_vcenter/sdk',
|
||||
'username' => 'test@test.fr',
|
||||
'password' => 'xxxx'},
|
||||
},
|
||||
);
|
||||
|
||||
'other' and 'default' are containers name.
|
||||
|
||||
Client Usage
|
||||
------------
|
||||
|
||||
Check vmtools states of virtual machines (with name matching the regexp 'prd'):
|
||||
::
|
||||
|
||||
$ perl centreon_plugins.pl --plugin=apps::vmware::connector::plugin --custommode=connector --connector-hostname=127.0.0.1 --container=default --verbose --mode=tools-vm --display-description --vm-hostname='prd' --filter
|
||||
WARNING: 1 VM with VMTools not installed |
|
||||
vmtools not installed:
|
||||
prd-Reporting - 10.0.0.1 [description xxxx]
|
||||
|
||||
Check datastore IOPs of virtual machines (with name matching the regexp 'centreon-central-1|Formation'):
|
||||
::
|
||||
|
||||
$ perl centreon_plugins.pl --plugin=apps::vmware::connector::plugin --custommode=connector --connector-hostname=127.0.0.1 --container=default --verbose --mode=datastore-vm --vm-hostname='centreon-central-1|Formation' --filter
|
||||
OK: All Datastore IOPS counters are ok | 'riops_Formation-Reporting - 10.30.2.89_R&D-BI'=0.00iops;;;0; 'wiops_Formation-Reporting - 10.30.2.89_R&D-BI'=1.43iops;;;0; 'riops_centreon-central-1_INTEGRATION'=0.00iops;;;0; 'wiops_centreon-central-1_INTEGRATION'=0.60iops;;;0;
|
||||
'Formation-Reporting - 10.30.2.89' read iops on 'R&D-BI' is 0.00
|
||||
'Formation-Reporting - 10.30.2.89' write iops on 'R&D-BI' is 1.43
|
||||
'centreon-central-1' read iops on 'INTEGRATION' is 0.00
|
||||
'centreon-central-1' write iops on 'INTEGRATION' is 0.60
|
||||
|
||||
Check the health of ESX Servers:
|
||||
::
|
||||
|
||||
$ perl centreon_plugins.pl --plugin=apps::vmware::connector::plugin --custommode=connector --connector-hostname=127.0.0.1 --container=default --verbose --mode=health-host --esx-hostname='.*' --filter --disconnect-status='ok'
|
||||
OK: All ESX health checks are ok | 'problems_srvi-clus-esx-n2.merethis.net'=0;;;0;299 'problems_srvi-clus-esx-n1.merethis.net'=0;;;0;299 'problems_srvi-clus-esx-n4.merethis.net'=0;;;0;186 'problems_srvi-clus-esx-n3.merethis.net'=0;;;0;186
|
||||
Checking srvi-clus-esx-n2.merethis.net
|
||||
299 health checks are green
|
||||
Checking srvi-clus-esx-n1.merethis.net
|
||||
299 health checks are green
|
||||
Checking srvi-clus-esx-n4.merethis.net
|
||||
186 health checks are green
|
||||
Checking srvi-clus-esx-n3.merethis.net
|
||||
186 health checks are green
|
||||
|
||||
Troubleshooting
|
||||
---------------
|
||||
|
||||
It is possible to get this kind of errors in the « logs » of « centreon-vmware »:
|
||||
::
|
||||
|
||||
...SOAP request error - possibly a protocol issue: read failed: error:1408F119:SSL routines:SSL3_GET_RECORD:decryption failed or bad record mac...
|
||||
|
||||
VMWare Perl SDK sometimes generates this error that does not alter the behaviour of the connector. The bug comes from OpenSSL. It should be fix in OpenSSL 1.0.1h (CVE-2010-5298).
|
||||
|
||||
You can have the following error returns by the connector:
|
||||
::
|
||||
|
||||
# perl centreon_plugins.pl --plugin=apps::vmware::connector::plugin ...
|
||||
Cannot get value for counters...
|
||||
|
||||
Please check that your VirtualCenter and ESX time synchronization. Most of the time, the server with the connector and/or VirtualCenter/ESX are not well synchronized.
|
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
|
@ -0,0 +1,16 @@
|
|||
.. Centreon ESXD documentation master file, created by
|
||||
sphinx-quickstart on Mon Apr 22 11:17:38 2013.
|
||||
You can adapt this file completely to your liking, but it should at least
|
||||
contain the root `toctree` directive.
|
||||
|
||||
Welcome to Centreon VMWare's documentation!
|
||||
===========================================
|
||||
|
||||
Contents:
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
installation/index
|
||||
exploitation/index
|
||||
|
|
@ -0,0 +1,303 @@
|
|||
============
|
||||
Installation
|
||||
============
|
||||
|
||||
Prerequisites
|
||||
=============
|
||||
|
||||
Software Recommandations
|
||||
````````````````````````
|
||||
|
||||
The "centreon-vmware" connector has been only tested on red-hat 5 and 6 with rpms.
|
||||
Installation on other system should be possible.
|
||||
|
||||
====================== =====================
|
||||
Software Version
|
||||
====================== =====================
|
||||
VMWare SDK Perl 5.1.0-780721
|
||||
Perl 5.8
|
||||
centreon-vmware 2.0.0
|
||||
perl-centreon-base 2.6.0
|
||||
centreon-plugins-base 1.11
|
||||
ZeroMQ 4.x
|
||||
Perl Date::Parse 1.x
|
||||
Perl ZMQ::LibZMQ4 0.01
|
||||
Perl ZMQ::Constants 1.04
|
||||
====================== =====================
|
||||
|
||||
How to install from sources is explained in the current documentation.
|
||||
|
||||
Hardware Recommandations
|
||||
````````````````````````
|
||||
|
||||
Hardware prerequisites will depend of check numbers. Minimal used resources are :
|
||||
|
||||
* RAM : 512 Mo (May slightly increase with the number of checks).
|
||||
* CPU : same as poller server.
|
||||
|
||||
Centreon-vmware Installation - Debian Stretch
|
||||
=============================================
|
||||
|
||||
SDK Perl VMWare Installation
|
||||
````````````````````````````
|
||||
|
||||
The "centreon-vmware" connector uses SDK Perl VMWare for its operation. So we install it with VMWare recommandation (only tested with version below).
|
||||
|
||||
========================== ===================== ======================
|
||||
Dependency Version Repository
|
||||
========================== ===================== ======================
|
||||
libwww-perl 6.15 stretch
|
||||
libxml-libxml-perl 2.0128 stretch
|
||||
libclass-methodmaker-perl 2.24 stretch
|
||||
libcrypt-ssleay-perl 0.73 stretch
|
||||
libsoap-lite-perl 1.20 stretch
|
||||
libuuid-perl 0.27 stretch
|
||||
========================== ===================== ======================
|
||||
|
||||
Install following dependency:
|
||||
::
|
||||
|
||||
# apt-get install make libxml-libxml-perl libwww-perl libclass-methodmaker-perl libcrypt-ssleay-perl libsoap-lite-perl libuuid-perl libtext-template-perl
|
||||
|
||||
Download the Perl SDK VMWare and install it:
|
||||
::
|
||||
|
||||
# tar zxf VMware-vSphere-Perl-SDK-6.7.0-8156551.x86_64.tar.gz && cd vmware-vsphere-cli-distrib
|
||||
# perl Makefile.PL
|
||||
# make && make install
|
||||
|
||||
Requirements
|
||||
`````````````
|
||||
|
||||
Following prerequisites are mandatory for « centreon_vmware »:
|
||||
|
||||
* « zeromq » and Perl binding
|
||||
|
||||
centreon-vmware Installation with source
|
||||
````````````````````````````````````````
|
||||
|
||||
Install the following package:
|
||||
::
|
||||
|
||||
# aptitude install libzmq5
|
||||
|
||||
Install « zeromq » perl binding dependency (need to patch the installer: https://rt.cpan.org/Public/Bug/Display.html?id=122932):
|
||||
::
|
||||
|
||||
# apt-get install gcc libmodule-install-perl libzmq3-dev
|
||||
# wget https://github.com/lestrrat/p5-ZMQ/archive/master.zip
|
||||
# unzip master.zip
|
||||
# cd p5-ZMQ-master/ZMQ-LibZMQ4/
|
||||
# perl Makefile.PL
|
||||
# make && make install
|
||||
# cd p5-ZMQ-master/ZMQ-Constants/
|
||||
# perl Makefile.PL
|
||||
# make && make install
|
||||
|
||||
Download « centreon-vmware » archive, then install:
|
||||
::
|
||||
|
||||
# tar zxvf centreon-vmware-3.0.0.tar.gz
|
||||
# cd centreon-vmware-3.0.0
|
||||
# cp centreon_vmware.pl /usr/bin/
|
||||
|
||||
# mkdir -p /etc/centreon /var/log/centreon
|
||||
# useradd centreon
|
||||
# chown centreon:centreon /var/log/centreon
|
||||
# cp contrib/config/centreon_vmware-conf.pm /etc/centreon/centreon_vmware.pm
|
||||
# cp contrib/debian/centreon_vmware-systemd /lib/systemd/system/centreon_vmware.service
|
||||
# chmod 664 /lib/systemd/system/centreon_vmware.service
|
||||
|
||||
# mkdir -p /usr/share/perl5/centreon/vmware/ /usr/share/perl5/centreon/script/
|
||||
# cp centreon/vmware/* /usr/share/perl5/centreon/vmware/
|
||||
# cp centreon/script/centreon_vmware.pm /usr/share/perl5/centreon/script/
|
||||
|
||||
Configure "centreon-vmware" daemon to start at boot:
|
||||
::
|
||||
|
||||
# systemctl enable centreon_vmware.service
|
||||
|
||||
Install the client and dependency:
|
||||
::
|
||||
|
||||
# apt-get install libtimedate-perl
|
||||
# git clone http://git.centreon.com/centreon-plugins.git
|
||||
# cd centreon-plugins
|
||||
# mkdir -p /usr/lib/nagios/plugins/centreon/plugins/
|
||||
# cp centreon/plugins/* /usr/lib/nagios/plugins/centreon/plugins/
|
||||
# mkdir -p /usr/lib/nagios/plugins/apps/vmware/
|
||||
# cp -R apps/vmware/* /usr/lib/nagios/plugins/apps/vmware/
|
||||
# cp centreon_plugins.pl /usr/lib/nagios/plugins/
|
||||
|
||||
Centreon-vmware Installation - centos/rhel 5 systems
|
||||
====================================================
|
||||
|
||||
SDK Perl VMWare Installation
|
||||
````````````````````````````
|
||||
|
||||
The "centreon-vmware" connector uses SDK Perl VMWare for its operation. So we install it with VMWare recommandation (only tested with version below).
|
||||
|
||||
======================= ===================== ======================
|
||||
Dependency Version Repository
|
||||
======================= ===================== ======================
|
||||
perl-libwww-perl 5.805 redhat/centos base
|
||||
perl-XML-LibXML 1.58 redhat/centos base
|
||||
perl-Class-MethodMaker 2.18 ces standard
|
||||
perl-Crypt-SSLeay 0.51 redhat/centos base
|
||||
perl-SOAP-Lite 0.712 ces standard
|
||||
perl-UUID 0.04 ces standard
|
||||
perl-VMware-vSphere 5.1.0-780721.1 ces standard
|
||||
======================= ===================== ======================
|
||||
|
||||
Install following dependency:
|
||||
::
|
||||
|
||||
# yum install perl-VMware-vSphere
|
||||
|
||||
Requirements
|
||||
`````````````
|
||||
|
||||
Following prerequisites are mandatory for « centreon_vmware »:
|
||||
|
||||
* « centreon-plugins-base »: in repository ces standard
|
||||
* « zeromq » and Perl binding: in repository ces standard or EPEL
|
||||
|
||||
Following prerequisites are optional for « centreon_vmware »:
|
||||
|
||||
* « perl-TimeDate »: in repository redhat/centos base
|
||||
|
||||
centreon-vmware Installation with rpm
|
||||
`````````````````````````````````````
|
||||
|
||||
Install the connector:
|
||||
::
|
||||
|
||||
# yum install ces-plugins-Virtualization-VMWare-daemon
|
||||
|
||||
Install the client:
|
||||
::
|
||||
|
||||
# yum install ces-plugins-Virtualization-VMWare-client
|
||||
|
||||
centreon-vmware Installation with source
|
||||
````````````````````````````````````````
|
||||
|
||||
Download « centreon-vmware » archive, then install:
|
||||
::
|
||||
|
||||
# tar zxvf centreon-vmware-3.0.0.tar.gz
|
||||
# cd centreon-vmware-3.0.0
|
||||
# cp centreon_vmware.pl /usr/bin/
|
||||
|
||||
# mkdir -p /etc/centreon
|
||||
# cp contrib/config/centreon_vmware-conf.pm /etc/centreon/centreon_vmware.pm
|
||||
# cp contrib/redhat/centreon_vmware-init /etc/init.d/centreon_vmware
|
||||
# cp contrib/redhat/centreon_vmware-sysconfig /etc/sysconfig/centreon_vmware
|
||||
# chmod 775 /etc/init.d/centreon_vmware /usr/bin/centreon_vmware.pl
|
||||
|
||||
# mkdir -p /usr/lib/perl5/vendor_perl/5.8.8/centreon/vmware/ /usr/lib/perl5/vendor_perl/5.8.8/centreon/script/
|
||||
# cp centreon/vmware/* /usr/lib/perl5/vendor_perl/5.8.8/centreon/vmware/
|
||||
# cp centreon/script/centreon_vmware.pm /usr/lib/perl5/vendor_perl/5.8.8/centreon/script/
|
||||
|
||||
Configure "centreon-vmware" daemon to start at boot:
|
||||
::
|
||||
|
||||
# chkconfig --level 2345 centreon_vmware on
|
||||
|
||||
Install the client and dependency:
|
||||
::
|
||||
|
||||
# git clone http://git.centreon.com/centreon-plugins.git
|
||||
# cd centreon-plugins
|
||||
# mkdir -p /usr/lib/nagios/plugins/centreon/plugins/
|
||||
# cp centreon/plugins/* /usr/lib/nagios/plugins/centreon/plugins/
|
||||
# mkdir -p /usr/lib/nagios/plugins/apps/vmware/
|
||||
# cp -R apps/vmware/* /usr/lib/nagios/plugins/apps/vmware/
|
||||
# cp centreon_plugins.pl /usr/lib/nagios/plugins/
|
||||
|
||||
Centreon-vmware Installation - centos/rhel 6 systems & centos 7
|
||||
====================================================
|
||||
|
||||
SDK Perl VMWare Installation
|
||||
````````````````````````````
|
||||
|
||||
The "centreon-vmware" connector uses SDK Perl VMWare for its operation. So we install it with VMWare recommendation (only tested with version below).
|
||||
|
||||
======================= ===================== ======================
|
||||
Dependency Version Repository
|
||||
======================= ===================== ======================
|
||||
perl-libwww-perl 5.833 redhat/centos base
|
||||
perl-XML-LibXML 1.70 redhat/centos base
|
||||
perl-Class-MethodMaker 2.16 redhat/centos base
|
||||
perl-Crypt-SSLeay 0.57 redhat/centos base
|
||||
perl-SOAP-Lite 0.710.10 redhat/centos base
|
||||
perl-UUID 0.04 ces standard
|
||||
perl-VMware-vSphere 5.1.0-780721.1 ces standard
|
||||
======================= ===================== ======================
|
||||
|
||||
Install following dependency:
|
||||
::
|
||||
|
||||
root # yum install perl-VMware-vSphere
|
||||
|
||||
Requirements
|
||||
````````````
|
||||
|
||||
Following prerequisites are mandatory for « centreon_vmware »:
|
||||
|
||||
* « perl-centreon-base »: module since Centreon 2.5 (repository ces standard)
|
||||
* « centreon-plugins-base »: in repository ces standard
|
||||
* « zeromq » and Perl binding: in repository ces standard or EPEL
|
||||
|
||||
Following prerequisites are optional for « centreon_vmware »:
|
||||
|
||||
* « perl-TimeDate »: in repository redhat/centos base
|
||||
|
||||
centreon-vmware Installation with rpm
|
||||
`````````````````````````````````````
|
||||
|
||||
Install the connector:
|
||||
::
|
||||
|
||||
# yum install centreon-plugin-Virtualization-VMWare-daemon
|
||||
|
||||
Install the client:
|
||||
::
|
||||
|
||||
# yum install centreon-plugin-Virtualization-Vmware2-Connector-Plugin
|
||||
|
||||
centreon-vmware Installation with source
|
||||
````````````````````````````````````````
|
||||
|
||||
Download « centreon-vmware » archive, then install:
|
||||
::
|
||||
|
||||
# tar zxvf centreon-vmware-3.0.0.tar.gz
|
||||
# cd centreon-vmware-3.0.0
|
||||
# cp centreon_vmware.pl /usr/bin/
|
||||
|
||||
# mkdir -p /etc/centreon
|
||||
# cp contrib/config/centreon_vmware-conf.pm /etc/centreon/centreon_vmware.pm
|
||||
# cp contrib/redhat/centreon_vmware-init /etc/init.d/centreon_vmware
|
||||
# cp contrib/redhat/centreon_vmware-sysconfig /etc/sysconfig/centreon_vmware
|
||||
# chmod 775 /etc/init.d/centreon_vmware /usr/bin/centreon_vmware.pl
|
||||
|
||||
# mkdir -p /usr/share/perl5/vendor_perl/centreon/vmware/ /usr/share/perl5/vendor_perl/centreon/script/
|
||||
# cp centreon/vmware/* /usr/share/perl5/vendor_perl/centreon/vmware/
|
||||
# cp centreon/script/centreon_vmware.pm /usr/share/perl5/vendor_perl/centreon/script/
|
||||
|
||||
Configure "centreon-vmware" daemon to start at boot:
|
||||
::
|
||||
|
||||
# chkconfig --level 2345 centreon_vmware on
|
||||
|
||||
Install the client and dependency:
|
||||
::
|
||||
|
||||
# git clone http://git.centreon.com/centreon-plugins.git
|
||||
# cd centreon-plugins
|
||||
# mkdir -p /usr/lib/nagios/plugins/centreon/plugins/
|
||||
# cp centreon/plugins/* /usr/lib/nagios/plugins/centreon/plugins/
|
||||
# mkdir -p /usr/lib/nagios/plugins/apps/vmware/
|
||||
# cp -R apps/vmware/* /usr/lib/nagios/plugins/apps/vmware/
|
||||
# cp centreon_plugins.pl /usr/lib/nagios/plugins/
|
|
@ -0,0 +1,177 @@
|
|||
# Makefile for Sphinx documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line.
|
||||
SPHINXOPTS =
|
||||
SPHINXBUILD = sphinx-build
|
||||
PAPER =
|
||||
BUILDDIR = _build
|
||||
|
||||
# User-friendly check for sphinx-build
|
||||
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
|
||||
$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
|
||||
endif
|
||||
|
||||
# Internal variables.
|
||||
PAPEROPT_a4 = -D latex_paper_size=a4
|
||||
PAPEROPT_letter = -D latex_paper_size=letter
|
||||
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
|
||||
# the i18n builder cannot share the environment and doctrees with the others
|
||||
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
|
||||
|
||||
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
|
||||
|
||||
help:
|
||||
@echo "Please use \`make <target>' where <target> is one of"
|
||||
@echo " html to make standalone HTML files"
|
||||
@echo " dirhtml to make HTML files named index.html in directories"
|
||||
@echo " singlehtml to make a single large HTML file"
|
||||
@echo " pickle to make pickle files"
|
||||
@echo " json to make JSON files"
|
||||
@echo " htmlhelp to make HTML files and a HTML help project"
|
||||
@echo " qthelp to make HTML files and a qthelp project"
|
||||
@echo " devhelp to make HTML files and a Devhelp project"
|
||||
@echo " epub to make an epub"
|
||||
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
|
||||
@echo " latexpdf to make LaTeX files and run them through pdflatex"
|
||||
@echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
|
||||
@echo " text to make text files"
|
||||
@echo " man to make manual pages"
|
||||
@echo " texinfo to make Texinfo files"
|
||||
@echo " info to make Texinfo files and run them through makeinfo"
|
||||
@echo " gettext to make PO message catalogs"
|
||||
@echo " changes to make an overview of all changed/added/deprecated items"
|
||||
@echo " xml to make Docutils-native XML files"
|
||||
@echo " pseudoxml to make pseudoxml-XML files for display purposes"
|
||||
@echo " linkcheck to check all external links for integrity"
|
||||
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILDDIR)/*
|
||||
|
||||
html:
|
||||
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
|
||||
|
||||
dirhtml:
|
||||
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
|
||||
|
||||
singlehtml:
|
||||
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
|
||||
@echo
|
||||
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
|
||||
|
||||
pickle:
|
||||
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
|
||||
@echo
|
||||
@echo "Build finished; now you can process the pickle files."
|
||||
|
||||
json:
|
||||
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
|
||||
@echo
|
||||
@echo "Build finished; now you can process the JSON files."
|
||||
|
||||
htmlhelp:
|
||||
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run HTML Help Workshop with the" \
|
||||
".hhp project file in $(BUILDDIR)/htmlhelp."
|
||||
|
||||
qthelp:
|
||||
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
|
||||
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
|
||||
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/CentreonESXD.qhcp"
|
||||
@echo "To view the help file:"
|
||||
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/CentreonESXD.qhc"
|
||||
|
||||
devhelp:
|
||||
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
|
||||
@echo
|
||||
@echo "Build finished."
|
||||
@echo "To view the help file:"
|
||||
@echo "# mkdir -p $$HOME/.local/share/devhelp/CentreonESXD"
|
||||
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/CentreonESXD"
|
||||
@echo "# devhelp"
|
||||
|
||||
epub:
|
||||
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
|
||||
@echo
|
||||
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
|
||||
|
||||
latex:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo
|
||||
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
|
||||
@echo "Run \`make' in that directory to run these through (pdf)latex" \
|
||||
"(use \`make latexpdf' here to do that automatically)."
|
||||
|
||||
latexpdf:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo "Running LaTeX files through pdflatex..."
|
||||
$(MAKE) -C $(BUILDDIR)/latex all-pdf
|
||||
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
|
||||
|
||||
latexpdfja:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo "Running LaTeX files through platex and dvipdfmx..."
|
||||
$(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
|
||||
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
|
||||
|
||||
text:
|
||||
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
|
||||
@echo
|
||||
@echo "Build finished. The text files are in $(BUILDDIR)/text."
|
||||
|
||||
man:
|
||||
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
|
||||
@echo
|
||||
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
|
||||
|
||||
texinfo:
|
||||
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
|
||||
@echo
|
||||
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
|
||||
@echo "Run \`make' in that directory to run these through makeinfo" \
|
||||
"(use \`make info' here to do that automatically)."
|
||||
|
||||
info:
|
||||
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
|
||||
@echo "Running Texinfo files through makeinfo..."
|
||||
make -C $(BUILDDIR)/texinfo info
|
||||
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
|
||||
|
||||
gettext:
|
||||
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
|
||||
@echo
|
||||
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
|
||||
|
||||
changes:
|
||||
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
|
||||
@echo
|
||||
@echo "The overview file is in $(BUILDDIR)/changes."
|
||||
|
||||
linkcheck:
|
||||
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
|
||||
@echo
|
||||
@echo "Link check complete; look for any errors in the above output " \
|
||||
"or in $(BUILDDIR)/linkcheck/output.txt."
|
||||
|
||||
doctest:
|
||||
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
|
||||
@echo "Testing of doctests in the sources finished, look at the " \
|
||||
"results in $(BUILDDIR)/doctest/output.txt."
|
||||
|
||||
xml:
|
||||
$(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
|
||||
@echo
|
||||
@echo "Build finished. The XML files are in $(BUILDDIR)/xml."
|
||||
|
||||
pseudoxml:
|
||||
$(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
|
||||
@echo
|
||||
@echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
|
|
@ -0,0 +1,248 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Centreon ESXD documentation build configuration file, created by
|
||||
# sphinx-quickstart on Mon Apr 22 11:17:38 2013.
|
||||
#
|
||||
# This file is execfile()d with the current directory set to its containing dir.
|
||||
#
|
||||
# Note that not all possible configuration values are present in this
|
||||
# autogenerated file.
|
||||
#
|
||||
# All configuration values have a default; values that are commented out
|
||||
# serve to show the default.
|
||||
|
||||
import sys, os
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
#sys.path.insert(0, os.path.abspath('.'))
|
||||
|
||||
# -- General configuration -----------------------------------------------------
|
||||
|
||||
# If your documentation needs a minimal Sphinx version, state it here.
|
||||
#needs_sphinx = '1.0'
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be extensions
|
||||
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
|
||||
extensions = []
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
|
||||
# The suffix of source filenames.
|
||||
source_suffix = '.rst'
|
||||
|
||||
# The encoding of source files.
|
||||
#source_encoding = 'utf-8-sig'
|
||||
|
||||
# The master toctree document.
|
||||
master_doc = 'index'
|
||||
|
||||
# General information about the project.
|
||||
project = u'Centreon VMWare'
|
||||
copyright = u'2015, Centreon'
|
||||
|
||||
# The version info for the project you're documenting, acts as replacement for
|
||||
# |version| and |release|, also used in various other places throughout the
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = '2.0'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = '2.0.0'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
#language = None
|
||||
|
||||
# There are two options for replacing |today|: either, you set today to some
|
||||
# non-false value, then it is used:
|
||||
#today = ''
|
||||
# Else, today_fmt is used as the format for a strftime call.
|
||||
#today_fmt = '%B %d, %Y'
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
exclude_patterns = ['_build']
|
||||
|
||||
# The reST default role (used for this markup: `text`) to use for all documents.
|
||||
#default_role = None
|
||||
|
||||
# If true, '()' will be appended to :func: etc. cross-reference text.
|
||||
#add_function_parentheses = True
|
||||
|
||||
# If true, the current module name will be prepended to all description
|
||||
# unit titles (such as .. function::).
|
||||
#add_module_names = True
|
||||
|
||||
# If true, sectionauthor and moduleauthor directives will be shown in the
|
||||
# output. They are ignored by default.
|
||||
#show_authors = False
|
||||
|
||||
# The name of the Pygments (syntax highlighting) style to use.
|
||||
pygments_style = 'sphinx'
|
||||
|
||||
# A list of ignored prefixes for module index sorting.
|
||||
#modindex_common_prefix = []
|
||||
|
||||
# If true, keep warnings as "system message" paragraphs in the built documents.
|
||||
#keep_warnings = False
|
||||
|
||||
|
||||
# -- Options for HTML output ---------------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
html_theme = 'default'
|
||||
|
||||
# Theme options are theme-specific and customize the look and feel of a theme
|
||||
# further. For a list of options available for each theme, see the
|
||||
# documentation.
|
||||
#html_theme_options = {}
|
||||
|
||||
# Add any paths that contain custom themes here, relative to this directory.
|
||||
#html_theme_path = []
|
||||
|
||||
# The name for this set of Sphinx documents. If None, it defaults to
|
||||
# "<project> v<release> documentation".
|
||||
#html_title = None
|
||||
|
||||
# A shorter title for the navigation bar. Default is the same as html_title.
|
||||
#html_short_title = None
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top
|
||||
# of the sidebar.
|
||||
#html_logo = None
|
||||
|
||||
# The name of an image file (within the static path) to use as favicon of the
|
||||
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
|
||||
# pixels large.
|
||||
#html_favicon = None
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ['_static']
|
||||
|
||||
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
|
||||
# using the given strftime format.
|
||||
#html_last_updated_fmt = '%b %d, %Y'
|
||||
|
||||
# If true, SmartyPants will be used to convert quotes and dashes to
|
||||
# typographically correct entities.
|
||||
#html_use_smartypants = True
|
||||
|
||||
# Custom sidebar templates, maps document names to template names.
|
||||
#html_sidebars = {}
|
||||
|
||||
# Additional templates that should be rendered to pages, maps page names to
|
||||
# template names.
|
||||
#html_additional_pages = {}
|
||||
|
||||
# If false, no module index is generated.
|
||||
#html_domain_indices = True
|
||||
|
||||
# If false, no index is generated.
|
||||
#html_use_index = True
|
||||
|
||||
# If true, the index is split into individual pages for each letter.
|
||||
#html_split_index = False
|
||||
|
||||
# If true, links to the reST sources are added to the pages.
|
||||
#html_show_sourcelink = True
|
||||
|
||||
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
|
||||
#html_show_sphinx = True
|
||||
|
||||
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
|
||||
#html_show_copyright = True
|
||||
|
||||
# If true, an OpenSearch description file will be output, and all pages will
|
||||
# contain a <link> tag referring to it. The value of this option must be the
|
||||
# base URL from which the finished HTML is served.
|
||||
#html_use_opensearch = ''
|
||||
|
||||
# This is the file name suffix for HTML files (e.g. ".xhtml").
|
||||
#html_file_suffix = None
|
||||
|
||||
# Output file base name for HTML help builder.
|
||||
htmlhelp_basename = 'CentreonESXDdoc'
|
||||
|
||||
|
||||
# -- Options for LaTeX output --------------------------------------------------
|
||||
|
||||
latex_elements = {
|
||||
# The paper size ('letterpaper' or 'a4paper').
|
||||
#'papersize': 'letterpaper',
|
||||
|
||||
# The font size ('10pt', '11pt' or '12pt').
|
||||
#'pointsize': '10pt',
|
||||
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
#'preamble': '',
|
||||
}
|
||||
|
||||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
# (source start file, target name, title, author, documentclass [howto/manual]).
|
||||
latex_documents = [
|
||||
('index', 'CentreonESXD.tex', u'Centreon ESXD Documentation',
|
||||
u'Merethis', 'manual'),
|
||||
]
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top of
|
||||
# the title page.
|
||||
#latex_logo = None
|
||||
|
||||
# For "manual" documents, if this is true, then toplevel headings are parts,
|
||||
# not chapters.
|
||||
#latex_use_parts = False
|
||||
|
||||
# If true, show page references after internal links.
|
||||
#latex_show_pagerefs = False
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
#latex_show_urls = False
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
#latex_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
#latex_domain_indices = True
|
||||
|
||||
|
||||
# -- Options for manual page output --------------------------------------------
|
||||
|
||||
# One entry per manual page. List of tuples
|
||||
# (source start file, name, description, authors, manual section).
|
||||
man_pages = [
|
||||
('index', 'centreonesxd', u'Centreon ESXD Documentation',
|
||||
[u'Merethis'], 1)
|
||||
]
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
#man_show_urls = False
|
||||
|
||||
|
||||
# -- Options for Texinfo output ------------------------------------------------
|
||||
|
||||
# Grouping the document tree into Texinfo files. List of tuples
|
||||
# (source start file, target name, title, author,
|
||||
# dir menu entry, description, category)
|
||||
texinfo_documents = [
|
||||
('index', 'CentreonESXD', u'Centreon ESXD Documentation',
|
||||
u'Merethis', 'CentreonESXD', 'One line description of project.',
|
||||
'Miscellaneous'),
|
||||
]
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
#texinfo_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
#texinfo_domain_indices = True
|
||||
|
||||
# How to display URL addresses: 'footnote', 'no', or 'inline'.
|
||||
#texinfo_show_urls = 'footnote'
|
||||
|
||||
# If true, do not generate a @detailmenu in the "Top" node's menu.
|
||||
#texinfo_no_detailmenu = False
|
|
@ -0,0 +1,121 @@
|
|||
============
|
||||
Exploitation
|
||||
============
|
||||
|
||||
Principes Généraux
|
||||
------------------
|
||||
|
||||
Centreon-esxd est un programme Perl chargé de récupérer des indicateurs VMWare. Ce programme utilise le SDK Perl fourni par VMWare afin de se connecter et récupérer les informations d'un (ou plusieurs) VirtualCenter. Pour cela il effectue une connexion TCP avec le(s) VirtualCenter.
|
||||
|
||||
Par défaut, « centreon-vmware » lance au moins deux processus (nommé respectivement « handle-client », « handle-vsphere-xxxx ») :
|
||||
|
||||
*« handle-client »*:
|
||||
*Processus en attente des demandes clientes.*
|
||||
|
||||
Voici le fonctionnement :
|
||||
|
||||
- Un client se connecte.
|
||||
- Le client demande un indicateur de supervision sur un VirtualCenter.
|
||||
- Le processus « handle-client » fourni cette demande au processus « handle-vsphere-xxxx ».
|
||||
- Une réponse est fournie par « handle-vsphere-xxxx » à « handle-client ».
|
||||
- Le processus « handle-client » fourni la réponse au client.
|
||||
|
||||
*« handle-vsphere-xxxx »*:
|
||||
*Processus ayant le rôle de se connecter et garder ouverte une session avec son VirtualCenter (De plus, dans un souci de performances, un cache de description des données de performances est créé).*
|
||||
|
||||
Enfin, ce processus récupère les indicateurs VMWare en créant un sous-processus par demande.
|
||||
|
||||
Centreon-vmware nécessite l'utilisation d'un (ou plusieurs) VirtualCenter (ou ESX).
|
||||
|
||||
Voici un exemple d'architecture éclaté :
|
||||
|
||||
.. image:: ../images/archi.png
|
||||
|
||||
Mode de fonctionnement
|
||||
----------------------
|
||||
|
||||
Le programme « centreon-vmware » fonctionne uniquement en mode « daemon ». (dans le sens où il ne peut fournir les indicateurs sans l'utilisation d'un client).
|
||||
|
||||
Configuration du connecteur
|
||||
---------------------------
|
||||
|
||||
Le daemon « centreon-vmware » possède un fichier de configuration « centreon_vmware.pm » de la forme suivante :
|
||||
::
|
||||
|
||||
%centreon_vmware_config = (
|
||||
vsphere_server => {
|
||||
'default' => {'url' => 'https://vcenter/sdk',
|
||||
'username' => 'test@test.fr',
|
||||
'password' => 'xxxx'},
|
||||
}
|
||||
);
|
||||
|
||||
L'attribut « vsphere_server » permet de configurer les accès aux différents VirtualCenter.
|
||||
Dans le cas ou il y a plusieurs VirtualCenters, la configuration devient (noter la "," de séparation) :
|
||||
::
|
||||
|
||||
%centreon_vmware_config = (
|
||||
vsphere_server => {
|
||||
'default' => {'url' => 'https://vcenter/sdk',
|
||||
'username' => 'test@test.fr',
|
||||
'password' => 'xxxx'},
|
||||
'other' => {'url' => 'https://other_vcenter/sdk',
|
||||
'username' => 'test@test.fr',
|
||||
'password' => 'xxxx'},
|
||||
}
|
||||
);
|
||||
|
||||
'other' et 'default' sont des containeurs.
|
||||
|
||||
Client Usage
|
||||
------------
|
||||
|
||||
Vérifie l'état des VMTools des machines virtuelles avec 'prd' dans leur nom:
|
||||
::
|
||||
|
||||
$ perl centreon_plugins.pl --plugin=apps::vmware::connector::plugin --custommode=connector --connector-hostname=127.0.0.1 --container=default --verbose --mode=tools-vm --display-description --vm-hostname='prd' --filter
|
||||
WARNING: 1 VM with VMTools not installed |
|
||||
vmtools not installed:
|
||||
prd-Reporting - 10.0.0.1 [description xxxx]
|
||||
|
||||
Vérifie les IOPs des machines virtuelles (avec 'centreon-central-1|Formation' dans leur nom. Cela est une expression régulière) sur leurs datastores:
|
||||
::
|
||||
|
||||
$ perl centreon_plugins.pl --plugin=apps::vmware::connector::plugin --custommode=connector --connector-hostname=127.0.0.1 --container=default --verbose --mode=datastore-vm --vm-hostname='centreon-central-1|Formation' --filter
|
||||
OK: All Datastore IOPS counters are ok | 'riops_Formation-Reporting - 10.30.2.89_R&D-BI'=0.00iops;;;0; 'wiops_Formation-Reporting - 10.30.2.89_R&D-BI'=1.43iops;;;0; 'riops_centreon-central-1_INTEGRATION'=0.00iops;;;0; 'wiops_centreon-central-1_INTEGRATION'=0.60iops;;;0;
|
||||
'Formation-Reporting - 10.30.2.89' read iops on 'R&D-BI' is 0.00
|
||||
'Formation-Reporting - 10.30.2.89' write iops on 'R&D-BI' is 1.43
|
||||
'centreon-central-1' read iops on 'INTEGRATION' is 0.00
|
||||
'centreon-central-1' write iops on 'INTEGRATION' is 0.60
|
||||
|
||||
Vérifie l'état de santé des serveurs ESX:
|
||||
::
|
||||
|
||||
$ perl centreon_plugins.pl --plugin=apps::vmware::connector::plugin --custommode=connector --connector-hostname=127.0.0.1 --container=default --verbose --mode=health-host --esx-hostname='.*' --filter --disconnect-status='ok'
|
||||
OK: All ESX health checks are ok | 'problems_srvi-clus-esx-n2.merethis.net'=0;;;0;299 'problems_srvi-clus-esx-n1.merethis.net'=0;;;0;299 'problems_srvi-clus-esx-n4.merethis.net'=0;;;0;186 'problems_srvi-clus-esx-n3.merethis.net'=0;;;0;186
|
||||
Checking srvi-clus-esx-n2.merethis.net
|
||||
299 health checks are green
|
||||
Checking srvi-clus-esx-n1.merethis.net
|
||||
299 health checks are green
|
||||
Checking srvi-clus-esx-n4.merethis.net
|
||||
186 health checks are green
|
||||
Checking srvi-clus-esx-n3.merethis.net
|
||||
186 health checks are green
|
||||
|
||||
Troubleshooting
|
||||
---------------
|
||||
|
||||
Il est possible de retrouver des erreurs de ce type dans les « logs » de « centreon-esxd » :
|
||||
::
|
||||
|
||||
...SOAP request error - possibly a protocol issue: read failed: error:1408F119:SSL routines:SSL3_GET_RECORD:decryption failed or bad record mac...
|
||||
|
||||
Le SDK Perl VMWare génère cette erreur de temps en temps mais ne bloque pas le fonctionnement du connecteur. Le bug provient d'OpenSSL. Il devrait être fix dans la version 1.0.1h (CVE-2010-5298).
|
||||
|
||||
Le connecteur peut retourner l'erreur suivante:
|
||||
::
|
||||
|
||||
# perl centreon_plugins.pl --plugin=apps::vmware::connector::plugin ...
|
||||
Cannot get value for counters...
|
||||
|
||||
Vérifier la synchronisation du temps du VirtualCenter et de ses serveurs ESX. La plupart du temps, le serveur hébergeant le connecteur ou le VirtualCenter/ESX ne sont pas bien synchronisés.
|
Binary file not shown.
After Width: | Height: | Size: 29 KiB |
|
@ -0,0 +1,16 @@
|
|||
.. Centreon ESXD documentation master file, created by
|
||||
sphinx-quickstart on Mon Apr 22 11:17:38 2013.
|
||||
You can adapt this file completely to your liking, but it should at least
|
||||
contain the root `toctree` directive.
|
||||
|
||||
Welcome to Centreon VMWare's documentation!
|
||||
===========================================
|
||||
|
||||
Contents:
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
installation/index
|
||||
exploitation/index
|
||||
|
|
@ -0,0 +1,307 @@
|
|||
============
|
||||
Installation
|
||||
============
|
||||
|
||||
Pré-Requis
|
||||
==========
|
||||
|
||||
Préconisations logicielles
|
||||
``````````````````````````
|
||||
|
||||
Le connecteur "centreon-vmware" est testé et validé sur red-hat 6 uniquement avec des rpms.
|
||||
L'installation sur d'autres environnements n'est pas exclu mais non présenté dans ce document (Debian, ...).
|
||||
|
||||
====================== =====================
|
||||
Logiciels Version
|
||||
====================== =====================
|
||||
VMWare SDK Perl 5.1.0-780721
|
||||
Perl 5.8
|
||||
centreon-vmware 2.0.0
|
||||
perl-centreon-base 2.5.0
|
||||
centreon-plugins-base 1.10
|
||||
ZeroMQ 4.x
|
||||
Perl Date::Parse 1.x
|
||||
Perl ZMQ::LibZMQ4 0.01
|
||||
Perl ZMQ::Constants 1.04
|
||||
====================== =====================
|
||||
|
||||
Il est expliqué comment installer par les sources dans ce document.
|
||||
|
||||
Préconisations matérielles
|
||||
``````````````````````````
|
||||
|
||||
Le matériel nécessaire dépend du nombre de demandes de vérifications. Par défaut, le connecteur n'effectue aucunes vérifications. Les ressources minimales sont de :
|
||||
|
||||
* mémoire vive : 512 Mo minimum (Peut sensiblement augmenter en fonction du nombre de contrôle).
|
||||
* CPU : même pré-requis que pour le serveur de collecte.
|
||||
|
||||
Centreon-vmware Installation - Debian Wheezy
|
||||
============================================
|
||||
|
||||
Installation du SDK Perl VMWare
|
||||
```````````````````````````````
|
||||
|
||||
Le connecteur « centreon-vmware » utilise le SDK Perl VMWare pour son fonctionnement. Nous allons donc l'installer en suivant les versions recommandées par VMWare (en dehors de ces versions, le fonctionnement n'est pas garanti).
|
||||
|
||||
========================== ===================== ======================
|
||||
Dependency Version Repository
|
||||
========================== ===================== ======================
|
||||
libwww-perl 6.15 stretch
|
||||
libxml-libxml-perl 2.0128 stretch
|
||||
libclass-methodmaker-perl 2.24 stretch
|
||||
libcrypt-ssleay-perl 0.73 stretch
|
||||
libsoap-lite-perl 1.20 stretch
|
||||
libuuid-perl 0.27 stretch
|
||||
========================== ===================== ======================
|
||||
|
||||
Installer les dépendances suivantes:
|
||||
::
|
||||
|
||||
# apt-get install make libxml-libxml-perl libwww-perl libclass-methodmaker-perl libcrypt-ssleay-perl libsoap-lite-perl libuuid-perl libtext-template-perl
|
||||
|
||||
Télécharger et installer le Perl SDK VMWare:
|
||||
::
|
||||
|
||||
# tar zxf VMware-vSphere-Perl-SDK-6.7.0-8156551.x86_64.tar.gz && cd vmware-vsphere-cli-distrib
|
||||
# perl Makefile.PL
|
||||
# make && make install
|
||||
|
||||
Pré-requis
|
||||
``````````
|
||||
|
||||
Les dépendances suivantes sont nécessaires pour le fonctionnement de « centreon_vmware »:
|
||||
|
||||
* « zeromq » et son module Perl
|
||||
|
||||
Installation de centreon-vmware par les sources
|
||||
```````````````````````````````````````````````
|
||||
|
||||
Installer le paquet suivant:
|
||||
::
|
||||
|
||||
# apt-get install libzmq5
|
||||
|
||||
Installer le perl binding « zeromq » (nécessite l'application du patch: https://rt.cpan.org/Public/Bug/Display.html?id=122932):
|
||||
::
|
||||
|
||||
# apt-get install gcc libmodule-install-perl libzmq3-dev
|
||||
# wget https://github.com/lestrrat/p5-ZMQ/archive/master.zip
|
||||
# unzip master.zip
|
||||
# cd p5-ZMQ-master/ZMQ-LibZMQ4/
|
||||
# perl Makefile.PL
|
||||
# make && make install
|
||||
# cd p5-ZMQ-master/ZMQ-Constants/
|
||||
# perl Makefile.PL
|
||||
# make && make install
|
||||
|
||||
Télécharger l'archive de « centreon-vmware » et installer le connecteur:
|
||||
::
|
||||
|
||||
# tar zxvf centreon-vmware-3.0.0.tar.gz
|
||||
# cd centreon-vmware-3.0.0
|
||||
# cp centreon_vmware.pl /usr/bin/
|
||||
|
||||
# mkdir -p /etc/centreon /var/log/centreon
|
||||
# useradd centreon
|
||||
# chown centreon:centreon /var/log/centreon
|
||||
# cp contrib/config/centreon_vmware-conf.pm /etc/centreon/centreon_vmware.pm
|
||||
# cp contrib/debian/centreon_vmware-systemd /lib/systemd/system/centreon_vmware.service
|
||||
# chmod 664 /lib/systemd/system/centreon_vmware.service
|
||||
|
||||
# mkdir -p /usr/share/perl5/centreon/vmware/ /usr/share/perl5/centreon/script/
|
||||
# cp centreon/vmware/* /usr/share/perl5/centreon/vmware/
|
||||
# cp centreon/script/centreon_vmware.pm /usr/share/perl5/centreon/script/
|
||||
|
||||
Activer le daemon « centreon-vmware » au démarrage:
|
||||
::
|
||||
|
||||
# systemctl enable centreon_vmware.service
|
||||
|
||||
Installer le client et les dépendances:
|
||||
::
|
||||
|
||||
# apt-get install libtimedate-perl
|
||||
# git clone http://git.centreon.com/centreon-plugins.git
|
||||
# cd centreon-plugins
|
||||
# mkdir -p /usr/lib/nagios/plugins/centreon/plugins/
|
||||
# cp centreon/plugins/* /usr/lib/nagios/plugins/centreon/plugins/
|
||||
# mkdir -p /usr/lib/nagios/plugins/apps/vmware/
|
||||
# cp -R apps/vmware/* /usr/lib/nagios/plugins/apps/vmware/
|
||||
# cp centreon_plugins.pl /usr/lib/nagios/plugins/
|
||||
|
||||
Installation de centreon-vmware - Environnement centos/rhel 5
|
||||
=============================================================
|
||||
|
||||
Installation du SDK Perl VMWare
|
||||
```````````````````````````````
|
||||
|
||||
Le connecteur « centreon-vmware » utilise le SDK Perl VMWare pour son fonctionnement. Nous allons donc l'installer en suivant les versions recommandées par VMWare (en dehors de ces versions, le fonctionnement n'est pas garanti).
|
||||
|
||||
======================= ===================== ======================
|
||||
Dépendance Version Dépôt
|
||||
======================= ===================== ======================
|
||||
perl-libwww-perl 5.805 redhat/centos base
|
||||
perl-XML-LibXML 1.58 redhat/centos base
|
||||
perl-Class-MethodMaker 2.18 ces standard
|
||||
perl-Crypt-SSLeay 0.51 redhat/centos base
|
||||
perl-SOAP-Lite 0.712 ces standard
|
||||
perl-UUID 0.04 ces standard
|
||||
perl-VMware-vSphere 5.1.0-780721.1 ces standard
|
||||
======================= ===================== ======================
|
||||
|
||||
Installer la dépendance suivante:
|
||||
::
|
||||
|
||||
# yum install perl-VMware-vSphere
|
||||
|
||||
Pré-requis
|
||||
``````````
|
||||
|
||||
Les dépendances suivantes sont nécessaires pour le fonctionnement de « centreon_vmware »:
|
||||
|
||||
* « centreon-plugins-base »: dépôt ces standard
|
||||
* « zeromq » and Perl binding: dépôt ces standard ou EPEL
|
||||
|
||||
Les dépendances suivantes sont optionnelles pour le fonctionnement de « centreon_vmware »:
|
||||
|
||||
* « perl-TimeDate »: dépôt redhat/centos base
|
||||
|
||||
Installation de centreon-vmware par rpm
|
||||
```````````````````````````````````````
|
||||
|
||||
Installer le connecteur:
|
||||
::
|
||||
|
||||
# yum install centreon-plugin-Virtualization-VMWare-daemon
|
||||
|
||||
Installer le client:
|
||||
::
|
||||
|
||||
# yum install centreon-plugin-Virtualization-Vmware2-Connector-Plugin
|
||||
|
||||
Installation de centreon-vmware par les sources
|
||||
```````````````````````````````````````````````
|
||||
|
||||
Télécharger l'archive de « centreon-vmware ».
|
||||
|
||||
Installer les fichiers:
|
||||
::
|
||||
|
||||
# tar zxvf centreon-vmware-2.0.0.tar.gz
|
||||
# cd centreon-vmware-2.0.0
|
||||
# cp centreon_vmware.pl /usr/bin/
|
||||
|
||||
# mkdir -p /etc/centreon
|
||||
# cp contrib/config/centreon_vmware-conf.pm /etc/centreon/centreon_vmware.pm
|
||||
# cp contrib/redhat/centreon_vmware-init /etc/init.d/centreon_vmware
|
||||
# cp contrib/redhat/centreon_vmware-sysconfig /etc/sysconfig/centreon_vmware
|
||||
# chmod 775 /etc/init.d/centreon_vmware /usr/bin/centreon_vmware.pl
|
||||
|
||||
# mkdir -p /usr/lib/perl5/vendor_perl/5.8.8/centreon/vmware/ /usr/lib/perl5/vendor_perl/5.8.8/centreon/script/
|
||||
# cp centreon/vmware/* /usr/lib/perl5/vendor_perl/5.8.8/centreon/vmware/
|
||||
# cp centreon/script/centreon_vmware.pm /usr/lib/perl5/vendor_perl/5.8.8/centreon/script/
|
||||
|
||||
Activer le daemon « centreon-vmware » au démarrage:
|
||||
::
|
||||
|
||||
# chkconfig --level 2345 centreon_vmware on
|
||||
|
||||
Installer le client et les dépendances:
|
||||
::
|
||||
|
||||
# git clone http://git.centreon.com/centreon-plugins.git
|
||||
# cd centreon-plugins
|
||||
# mkdir -p /usr/lib/nagios/plugins/centreon/plugins/
|
||||
# cp centreon/plugins/* /usr/lib/nagios/plugins/centreon/plugins/
|
||||
# mkdir -p /usr/lib/nagios/plugins/apps/vmware/
|
||||
# cp -R apps/vmware/* /usr/lib/nagios/plugins/apps/vmware/
|
||||
# cp centreon_plugins.pl /usr/lib/nagios/plugins/
|
||||
|
||||
Installation de centreon-vmware - Environnement centos/rhel 6
|
||||
=============================================================
|
||||
|
||||
Installation du SDK Perl VMWare
|
||||
```````````````````````````````
|
||||
|
||||
Le connecteur « centreon-vmware » utilise le SDK Perl VMWare pour son fonctionnement. Nous allons donc l'installer en suivant les versions recommandées par VMWare (en dehors de ces versions, le fonctionnement n'est pas garanti).
|
||||
|
||||
======================= ===================== ======================
|
||||
Dépendance Version Dépôt
|
||||
======================= ===================== ======================
|
||||
perl-libwww-perl 5.833 redhat/centos base
|
||||
perl-XML-LibXML 1.70 redhat/centos base
|
||||
perl-Class-MethodMaker 2.16 redhat/centos base
|
||||
perl-Crypt-SSLeay 0.57 redhat/centos base
|
||||
perl-SOAP-Lite 0.710.10 redhat/centos base
|
||||
perl-UUID 0.04 ces standard
|
||||
perl-VMware-vSphere 5.1.0-780721.1 ces standard
|
||||
======================= ===================== ======================
|
||||
|
||||
Installer la dépendance suivante:
|
||||
::
|
||||
|
||||
# yum install perl-VMware-vSphere
|
||||
|
||||
Pré-requis
|
||||
``````````
|
||||
|
||||
Les dépendances suivantes sont nécessaires pour le fonctionnement de « centreon_vmware »:
|
||||
|
||||
* « perl-centreon-base » : module est présent à partir de Centreon 2.5 (dépôt ces standard)
|
||||
* « centreon-plugins-base » : présent dans le dépôt ces standard
|
||||
* « zeromq » et le binding Perl : présent dans le dépôt ces standard ou EPEL
|
||||
|
||||
Les dépendances suivantes sont optionnelles pour le fonctionnement de « centreon_vmware »:
|
||||
|
||||
* « perl-TimeDate »: dépôt redhat/centos base
|
||||
|
||||
Installation de centreon-vmware par rpm
|
||||
```````````````````````````````````````
|
||||
|
||||
Installer le connecteur:
|
||||
::
|
||||
|
||||
# yum install ces-plugins-Virtualization-VMWare-daemon
|
||||
|
||||
Installer le client:
|
||||
::
|
||||
|
||||
# yum install ces-plugins-Virtualization-VMWare-client
|
||||
|
||||
Installation de centreon-vmware par les sources
|
||||
```````````````````````````````````````````````
|
||||
|
||||
Télécharger l'archive de « centreon-vmware ».
|
||||
|
||||
Installer le connecteur:
|
||||
::
|
||||
|
||||
# tar zxvf centreon-vmware-2.0.0.tar.gz
|
||||
# cd centreon-vmware-2.0.0
|
||||
# cp centreon_vmware.pl /usr/bin/
|
||||
|
||||
# mkdir -p /etc/centreon
|
||||
# cp contrib/config/centreon_vmware-conf.pm /etc/centreon/centreon_vmware.pm
|
||||
# cp contrib/redhat/centreon_vmware-init /etc/init.d/centreon_vmware
|
||||
# cp contrib/redhat/centreon_vmware-sysconfig /etc/sysconfig/centreon_vmware
|
||||
# chmod 775 /etc/init.d/centreon_vmware /usr/bin/centreon_vmware.pl
|
||||
|
||||
# mkdir -p /usr/share/perl5/vendor_perl/centreon/vmware/ /usr/share/perl5/vendor_perl/centreon/script/
|
||||
# cp centreon/vmware/* /usr/share/perl5/vendor_perl/centreon/vmware/
|
||||
# cp centreon/script/centreon_vmware.pm /usr/share/perl5/vendor_perl/centreon/script/
|
||||
|
||||
Activer le daemon « centreon-vmware » au démarrage:
|
||||
::
|
||||
|
||||
# chkconfig --level 2345 centreon_vmware on
|
||||
|
||||
Installer le client et les dépendances:
|
||||
::
|
||||
|
||||
# git clone http://git.centreon.com/centreon-plugins.git
|
||||
# cd centreon-plugins
|
||||
# mkdir -p /usr/lib/nagios/plugins/centreon/plugins/
|
||||
# cp -R centreon/plugins/* /usr/lib/nagios/plugins/centreon/plugins/
|
||||
# mkdir -p /usr/lib/nagios/plugins/apps/vmware/
|
||||
# cp -R apps/vmware/* /usr/lib/nagios/plugins/apps/vmware/
|
||||
# cp centreon_plugins.pl /usr/lib/nagios/plugins/
|
|
@ -0,0 +1,100 @@
|
|||
name: "centreon-plugin-Virtualization-VMWare-daemon"
|
||||
arch: "all"
|
||||
platform: "linux"
|
||||
version_schema: "none"
|
||||
version: "${VERSION}"
|
||||
release: "${RELEASE}${DIST}"
|
||||
section: "default"
|
||||
priority: "optional"
|
||||
maintainer: "Centreon <contact@centreon.com>"
|
||||
description: |
|
||||
Perl daemon to monitor VSphere Infrastructure
|
||||
Commit: @COMMIT_HASH@
|
||||
vendor: "Centreon"
|
||||
homepage: "https://centreon.com"
|
||||
license: "Apache-2.0"
|
||||
|
||||
replaces:
|
||||
- ces-plugins-Virtualization-VMWare-daemon
|
||||
- centreon-plugin-Virtualisation-VMWare-daemon
|
||||
conflicts:
|
||||
- ces-plugins-Virtualization-VMWare-daemon
|
||||
- centreon-plugin-Virtualisation-VMWare-daemon
|
||||
provides:
|
||||
- ces-plugins-Virtualization-VMWare-daemon
|
||||
- centreon-plugin-Virtualisation-VMWare-daemon
|
||||
|
||||
contents:
|
||||
- src: "../src/centreon/vmware"
|
||||
dst: "/usr/share/perl5/vendor_perl/centreon/vmware"
|
||||
packager: rpm
|
||||
- src: "../src/centreon/vmware"
|
||||
dst: "/usr/share/perl5/centreon/vmware"
|
||||
packager: deb
|
||||
|
||||
- src: "../src/centreon/script/centreon_vmware.pm"
|
||||
dst: "/usr/share/perl5/vendor_perl/centreon/script/centreon_vmware.pm"
|
||||
packager: rpm
|
||||
- src: "../src/centreon/script/centreon_vmware.pm"
|
||||
dst: "/usr/share/perl5/centreon/script/centreon_vmware.pm"
|
||||
packager: deb
|
||||
|
||||
- src: "../src/centreon_vmware.pl"
|
||||
dst: "/usr/bin/centreon_vmware.pl"
|
||||
file_info:
|
||||
mode: 0755
|
||||
|
||||
- src: "redhat/centreon_vmware-systemd"
|
||||
dst: "/etc/systemd/system/centreon_vmware.service"
|
||||
file_info:
|
||||
mode: 0755
|
||||
packager: rpm
|
||||
- src: "debian/centreon_vmware-systemd"
|
||||
dst: "/lib/systemd/system/centreon_vmware.service"
|
||||
file_info:
|
||||
mode: 0755
|
||||
packager: deb
|
||||
|
||||
- src: "redhat/centreon_vmware-sysconfig"
|
||||
dst: "/etc/sysconfig/centreon_vmware"
|
||||
packager: rpm
|
||||
- src: "debian/centreon_vmware-default"
|
||||
dst: "/etc/default/centreon_vmware"
|
||||
packager: deb
|
||||
|
||||
- src: "config/centreon_vmware-conf.pm"
|
||||
dst: "/etc/centreon/centreon_vmware.pm"
|
||||
type: config|noreplace
|
||||
packager: rpm
|
||||
- src: "config/centreon_vmware-conf.pm"
|
||||
dst: "/etc/centreon/centreon_vmware.pm.new"
|
||||
packager: deb
|
||||
|
||||
scripts:
|
||||
postinstall: ./scripts/postinstall.sh
|
||||
|
||||
overrides:
|
||||
rpm:
|
||||
depends:
|
||||
- perl-VMware-vSphere >= 5.1
|
||||
- perl(ZMQ::LibZMQ4)
|
||||
- perl(ZMQ::Constants)
|
||||
- perl(LWP::Protocol::https)
|
||||
- perl(IO::Socket::INET6)
|
||||
- perl(JSON::XS)
|
||||
- perl-Net-Curl
|
||||
deb:
|
||||
depends:
|
||||
- perl-vmware-vsphere
|
||||
- libzmq-libzmq4-perl
|
||||
- libzmq-constants-perl
|
||||
- liblwp-protocol-https-perl
|
||||
- libio-socket-inet6-perl
|
||||
- libjson-xs-perl
|
||||
- libnet-curl-perl
|
||||
- libtext-template-perl
|
||||
|
||||
rpm:
|
||||
signature:
|
||||
key_file: ${RPM_SIGNING_KEY_FILE}
|
||||
key_id: ${RPM_SIGNING_KEY_ID}
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
%centreon_vmware_config = (
|
||||
vsphere_server => {
|
||||
'default' => {'url' => 'https://vcenter/sdk',
|
||||
'username' => 'XXXXXX',
|
||||
'password' => 'XXXXXX'}
|
||||
}
|
||||
);
|
||||
|
||||
1;
|
|
@ -0,0 +1,2 @@
|
|||
# centreon_vmware command line options
|
||||
OPTIONS="--logfile=/var/log/centreon_vmware.log --severity=error"
|
|
@ -0,0 +1,105 @@
|
|||
#!/bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: centreon_vmware.pl
|
||||
# Required-Start: $local_fs $network
|
||||
# Required-Stop: $local_fs $network
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Should-Start:
|
||||
# Should-Stop:
|
||||
# Short-Description: Start daemon centreon_vmware.pl at boot
|
||||
# Description:
|
||||
### END INIT INFO
|
||||
|
||||
PKGNAME=centreon_vmware
|
||||
DESC="centreon-vmware"
|
||||
DAEMON=/usr/bin/centreon_vmware.pl
|
||||
PIDFILE=/var/run/centreon/centreon_vmware.pid
|
||||
FOLDER=/var/run/centreon/
|
||||
if [ ! -d "$FOLDER" ]; then # Control will enter here if $DIRECTORY doesn't exist.
|
||||
mkdir $FOLDER
|
||||
fi
|
||||
|
||||
if [ ! -x "${DAEMON}" ]; then
|
||||
echo "The program ${DAEMON} does not exists or is not executable"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
# Include the default user configuration if exists
|
||||
[ -r /etc/default/${PKGNAME} ] && . /etc/default/${PKGNAME}
|
||||
|
||||
# Load the VERBOSE setting and other rcS variables
|
||||
[ -f /etc/init/vars.sh ] && . /etc/init/vars.sh
|
||||
|
||||
# Define LSB log_* functions.
|
||||
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
if [ -z "${RUN_AT_STARTUP}" -o "${RUN_AT_STARTUP}" != "YES" ]; then
|
||||
log_warning_msg "Not starting $PKGNAME, edit /etc/default/$PKGNAME to start it."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ -z "${CENTREON_USER}" ]; then
|
||||
log_warning_msg "Not starting $PKGNAME, CENTREON_USER not set in /etc/default/$PKGNAME."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
do_start()
|
||||
{
|
||||
start-stop-daemon --start --background --quiet --pidfile ${PIDFILE} --exec ${DAEMON} \
|
||||
--chuid ${CENTREON_USER} --user ${CENTREON_USER} --test -- $OPTIONS
|
||||
[ "$?" = "0" ] || return 1
|
||||
start-stop-daemon --start --background --quiet --pidfile ${PIDFILE} --exec ${DAEMON} \
|
||||
--make-pidfile --chuid ${CENTREON_USER} --user ${CENTREON_USER} -- $OPTIONS
|
||||
[ "$?" = "0" ] || return 2
|
||||
return 0
|
||||
}
|
||||
|
||||
do_stop()
|
||||
{
|
||||
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --user ${CENTREON_USER} --pidfile ${PIDFILE}
|
||||
[ "$?" = "2" ] && return 2
|
||||
rm -rf ${PIDFILE}
|
||||
[ "$?" = 0 ] && return 0 || return 1
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
[ "${VERBOSE}" != "no" ] && log_daemon_msg "Starting ${DESC}" "${PKGNAME}"
|
||||
do_start
|
||||
case "$?" in
|
||||
0|1) [ "${VERBOSE}" != "no" ] && log_end_msg 0 ;;
|
||||
2) [ "${VERBOSE}" != "no" ] && log_end_msg 1 ;;
|
||||
esac
|
||||
;;
|
||||
stop)
|
||||
[ "${VERBOSE}" != no ] && log_daemon_msg "Stopping ${DESC}" "${PKGNAME}"
|
||||
do_stop
|
||||
case "$?" in
|
||||
0|1) [ "${VERBOSE}" != no ] && log_end_msg 0 ;;
|
||||
2) [ "${VERBOSE}" != no ] && log_end_msg 1 ;;
|
||||
esac
|
||||
;;
|
||||
status)
|
||||
status_of_proc ${DAEMON} ${PKGNAME} -p ${PIDFILE}
|
||||
;;
|
||||
restart|force-reload)
|
||||
[ "${VERBOSE}" != no ] && log_daemon_msg "Restarting ${DESC}" "${PKGNAME}"
|
||||
do_stop
|
||||
case "$?" in
|
||||
0|1)
|
||||
do_start
|
||||
case "$?" in
|
||||
0) log_end_msg 0 ;;
|
||||
1) log_end_msg 1 ;;
|
||||
*) log_end_msg 1 ;;
|
||||
esac
|
||||
;;
|
||||
*) log_end_msg 1 ;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
echo "Usage: ${SCRIPTNAME} (start|stop|status|restart|force-reload)" >&2
|
||||
exit 3
|
||||
esac
|
|
@ -0,0 +1,27 @@
|
|||
## Copyright 2016 Centreon
|
||||
##
|
||||
## Licensed under the Apache License, Version 2.0 (the "License");
|
||||
## you may not use this file except in compliance with the License.
|
||||
## You may obtain a copy of the License at
|
||||
##
|
||||
## http://www.apache.org/licenses/LICENSE-2.0
|
||||
##
|
||||
## Unless required by applicable law or agreed to in writing, software
|
||||
## distributed under the License is distributed on an "AS IS" BASIS,
|
||||
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
## See the License for the specific language governing permissions and
|
||||
## limitations under the License.
|
||||
##
|
||||
## For more information : contact@centreon.com
|
||||
##
|
||||
|
||||
[Unit]
|
||||
Description=Centreon VMWare
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/perl /usr/bin/centreon_vmware.pl --logfile=/var/log/centreon/centreon_vmware.log --severity=error
|
||||
Type=simple
|
||||
User=centreon
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
|
@ -0,0 +1,132 @@
|
|||
#! /bin/bash
|
||||
#
|
||||
# centreon_vmware Start/Stop the centreon_vmware daemon.
|
||||
#
|
||||
# chkconfig: 2345 80 20
|
||||
# description: centreon_vmware is a Centreon program that manage Vpshere Checks
|
||||
# processname: centreon_vmware.pl
|
||||
# config: /etc/centreon/centreon_vmware.pm
|
||||
# pidfile: /var/run/centreon_vmware.pid
|
||||
|
||||
# Source function library.
|
||||
. /etc/init.d/functions
|
||||
|
||||
binary=/usr/bin/centreon_vmware.pl
|
||||
servicename=$(basename "$0")
|
||||
OPTIONS=""
|
||||
user=root
|
||||
timeout=60
|
||||
start_timeout=5
|
||||
|
||||
pidfile=/var/run/centreon_vmware.pid
|
||||
|
||||
[ -e /etc/sysconfig/centreon_vmware ] && . /etc/sysconfig/centreon_vmware
|
||||
|
||||
# Check if we can find the binary.
|
||||
if [ ! -x $binary ]; then
|
||||
echo -n $"Starting $servicename.";
|
||||
failure $"Executable file $binary not found. Exiting."
|
||||
echo
|
||||
exit 2
|
||||
fi
|
||||
|
||||
start() {
|
||||
echo -n $"Starting $servicename: "
|
||||
if [ -e "$pidfile" ] && [ -n "$(cat $pidfile)" ] && [ -e "/proc/`cat $pidfile`" ]; then
|
||||
echo -n $"cannot start $servicename: $servicename is already running.";
|
||||
failure $"cannot start $servicename: $servicename already running.";
|
||||
echo
|
||||
return 1
|
||||
fi
|
||||
if [ ! -e "$pidfile" ] ; then
|
||||
pid=$(pidofproc $binary)
|
||||
if [ -n "$pid" ] ; then
|
||||
echo -n $"cannot start $servicename: $servicename is already running.";
|
||||
failure $"cannot start $servicename: $servicename already running.";
|
||||
echo
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$(id -u -n)" = "$user" ] ; then
|
||||
daemon --check centreon_vmware ''$binary' '$OPTIONS' > /dev/null 2>&1 &'
|
||||
else
|
||||
daemon --user $user --check centreon_vmware ''$binary' '$OPTIONS' > /dev/null 2>&1 &'
|
||||
fi
|
||||
|
||||
sleep 2
|
||||
|
||||
i=0
|
||||
while : ; do
|
||||
if [ "$i" -gt $start_timeout ] ; then
|
||||
failure $"service not launched"
|
||||
echo
|
||||
return 1
|
||||
fi
|
||||
pid=$(pidofproc $binary)
|
||||
if [ -n "$pid" ] ; then
|
||||
echo $pid > $pidfile
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
i=$(($i + 1))
|
||||
done
|
||||
success $"service launched"
|
||||
echo
|
||||
return 0
|
||||
}
|
||||
|
||||
stop() {
|
||||
echo -n $"Stopping $servicename: "
|
||||
if [ ! -e "$pidfile" ] || [ -z "$(cat $pidfile)" ] ; then
|
||||
killproc -d $timeout "$binary"
|
||||
else
|
||||
killproc -p "$pidfile" -d $timeout "$binary"
|
||||
fi
|
||||
RETVAL=$?
|
||||
echo
|
||||
return $RETVAL
|
||||
}
|
||||
|
||||
rhstatus() {
|
||||
status -p "$pidfile" "$binary"
|
||||
}
|
||||
|
||||
restart() {
|
||||
stop
|
||||
start
|
||||
}
|
||||
|
||||
reload() {
|
||||
echo -n $"Reloading $servicename daemon configuration: "
|
||||
killproc -p "$pidfile" "$binary" -HUP
|
||||
RETVAL=$?
|
||||
echo
|
||||
return $RETVAL
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
restart)
|
||||
restart
|
||||
;;
|
||||
reload)
|
||||
reload
|
||||
;;
|
||||
status)
|
||||
rhstatus
|
||||
;;
|
||||
condrestart)
|
||||
[ -f /var/lock/subsys/centreon_vmware ] && restart || :
|
||||
;;
|
||||
*)
|
||||
echo $"Usage: $0 {start|stop|status|reload|restart|condrestart}"
|
||||
exit 1
|
||||
esac
|
||||
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
# centreon_vmware command line options
|
||||
OPTIONS="--logfile=/var/log/centreon/centreon_vmware.log --severity=error"
|
|
@ -0,0 +1,27 @@
|
|||
## Copyright 2016 Centreon
|
||||
##
|
||||
## Licensed under the Apache License, Version 2.0 (the "License");
|
||||
## you may not use this file except in compliance with the License.
|
||||
## You may obtain a copy of the License at
|
||||
##
|
||||
## http://www.apache.org/licenses/LICENSE-2.0
|
||||
##
|
||||
## Unless required by applicable law or agreed to in writing, software
|
||||
## distributed under the License is distributed on an "AS IS" BASIS,
|
||||
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
## See the License for the specific language governing permissions and
|
||||
## limitations under the License.
|
||||
##
|
||||
## For more information : contact@centreon.com
|
||||
##
|
||||
|
||||
[Unit]
|
||||
Description=Centreon VMWare
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/perl /usr/bin/centreon_vmware.pl --logfile=/var/log/centreon/centreon_vmware.log --severity=error
|
||||
Type=simple
|
||||
User=centreon
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
if [ "$1" = "configure" ]; then # deb
|
||||
if [ ! -f "/etc/centreon/centreon_vmware.pm" ]; then
|
||||
mv /etc/centreon/centreon_vmware.pm.new /etc/centreon/centreon_vmware.pm
|
||||
fi
|
||||
fi
|
|
@ -0,0 +1,613 @@
|
|||
#!/usr/bin/perl
|
||||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::script::centreon_vmware;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use VMware::VIRuntime;
|
||||
use VMware::VILib;
|
||||
use ZMQ::LibZMQ4;
|
||||
use ZMQ::Constants qw(:all);
|
||||
use File::Basename;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
use POSIX ":sys_wait_h";
|
||||
use JSON::XS;
|
||||
use centreon::vmware::script;
|
||||
use centreon::vmware::common;
|
||||
use centreon::vmware::connector;
|
||||
|
||||
my ($centreon_vmware, $frontend);
|
||||
|
||||
BEGIN {
|
||||
# In new version version of LWP (version 6), the backend is now 'IO::Socket::SSL' (instead Crypt::SSLeay)
|
||||
# it's a hack if you unset that
|
||||
#$ENV{PERL_NET_HTTPS_SSL_SOCKET_CLASS} = "Net::SSL";
|
||||
|
||||
# The option is not omit to verify the certificate chain.
|
||||
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
|
||||
|
||||
eval {
|
||||
# required for new IO::Socket::SSL versions
|
||||
require IO::Socket::SSL;
|
||||
IO::Socket::SSL->import();
|
||||
IO::Socket::SSL::set_ctx_defaults( SSL_verify_mode => 0, SSL_no_shutdown => 1 );
|
||||
};
|
||||
}
|
||||
|
||||
use base qw(centreon::vmware::script);
|
||||
use vars qw(%centreon_vmware_config);
|
||||
|
||||
my $VERSION = '3.2.5';
|
||||
my %handlers = (TERM => {}, HUP => {}, CHLD => {});
|
||||
|
||||
my @load_modules = (
|
||||
'centreon::vmware::cmdalarmdatacenter',
|
||||
'centreon::vmware::cmdalarmhost',
|
||||
'centreon::vmware::cmdcountvmhost',
|
||||
'centreon::vmware::cmdcpucluster',
|
||||
'centreon::vmware::cmdcpuhost',
|
||||
'centreon::vmware::cmdcpuvm',
|
||||
'centreon::vmware::cmddatastorecountvm',
|
||||
'centreon::vmware::cmddatastoreio',
|
||||
'centreon::vmware::cmddatastoreiops',
|
||||
'centreon::vmware::cmddatastorehost',
|
||||
'centreon::vmware::cmddatastoresnapshot',
|
||||
'centreon::vmware::cmddatastorevm',
|
||||
'centreon::vmware::cmddatastoreusage',
|
||||
'centreon::vmware::cmddevicevm',
|
||||
'centreon::vmware::cmddiscovery',
|
||||
'centreon::vmware::cmdgetmap',
|
||||
'centreon::vmware::cmdhealthhost',
|
||||
'centreon::vmware::cmdlicenses',
|
||||
'centreon::vmware::cmdlimitvm',
|
||||
'centreon::vmware::cmdlistclusters',
|
||||
'centreon::vmware::cmdlistdatacenters',
|
||||
'centreon::vmware::cmdlistdatastores',
|
||||
'centreon::vmware::cmdlistnichost',
|
||||
'centreon::vmware::cmdmemhost',
|
||||
'centreon::vmware::cmdmaintenancehost',
|
||||
'centreon::vmware::cmdmemvm',
|
||||
'centreon::vmware::cmdnethost',
|
||||
'centreon::vmware::cmdnetvm',
|
||||
'centreon::vmware::cmdservicehost',
|
||||
'centreon::vmware::cmdsnapshotvm',
|
||||
'centreon::vmware::cmdstatuscluster',
|
||||
'centreon::vmware::cmdstatushost',
|
||||
'centreon::vmware::cmdstatusvm',
|
||||
'centreon::vmware::cmdstoragehost',
|
||||
'centreon::vmware::cmdswaphost',
|
||||
'centreon::vmware::cmdswapvm',
|
||||
'centreon::vmware::cmdthinprovisioningvm',
|
||||
'centreon::vmware::cmdtimehost',
|
||||
'centreon::vmware::cmdtoolsvm',
|
||||
'centreon::vmware::cmduptimehost',
|
||||
'centreon::vmware::cmdvmoperationcluster',
|
||||
'centreon::vmware::cmdvsanclusterusage'
|
||||
);
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $self = $class->SUPER::new('centreon_vmware');
|
||||
|
||||
bless $self, $class;
|
||||
$self->add_options(
|
||||
'config-extra=s' => \$self->{opt_extra}
|
||||
);
|
||||
|
||||
%{$self->{centreon_vmware_default_config}} =
|
||||
(
|
||||
credstore_use => 0,
|
||||
credstore_file => '/root/.vmware/credstore/vicredentials.xml',
|
||||
timeout_vsphere => 60,
|
||||
timeout => 60,
|
||||
timeout_kill => 30,
|
||||
dynamic_timeout_kill => 86400,
|
||||
refresh_keeper_session => 15,
|
||||
bind => '*',
|
||||
port => 5700,
|
||||
ipc_file => '/tmp/centreon_vmware/routing.ipc',
|
||||
case_insensitive => 0,
|
||||
vsphere_server => {
|
||||
#'default' => {'url' => 'https://XXXXXX/sdk',
|
||||
# 'username' => 'XXXXX',
|
||||
# 'password' => 'XXXXX'},
|
||||
#'testvc' => {'url' => 'https://XXXXXX/sdk',
|
||||
# 'username' => 'XXXXX',
|
||||
# 'password' => 'XXXXXX'}
|
||||
},
|
||||
vsan_sdk_path => '/usr/local/share/perl5/VMware'
|
||||
);
|
||||
|
||||
$self->{return_child} = {};
|
||||
$self->{stop} = 0;
|
||||
$self->{childs_vpshere_pid} = {};
|
||||
$self->{counter_stats} = {};
|
||||
$self->{whoaim} = undef; # to know which vsphere to connect
|
||||
$self->{modules_registry} = {};
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub init {
|
||||
my $self = shift;
|
||||
$self->SUPER::init();
|
||||
|
||||
# redefine to avoid out when we try modules
|
||||
$SIG{__DIE__} = undef;
|
||||
|
||||
if (!defined($self->{opt_extra})) {
|
||||
$self->{opt_extra} = "/etc/centreon/centreon_vmware.pm";
|
||||
}
|
||||
if (-f $self->{opt_extra}) {
|
||||
require $self->{opt_extra};
|
||||
} else {
|
||||
$self->{logger}->writeLogInfo("Can't find extra config file $self->{opt_extra}");
|
||||
}
|
||||
|
||||
$self->{centreon_vmware_config} = {%{$self->{centreon_vmware_default_config}}, %centreon_vmware_config};
|
||||
|
||||
foreach my $name (keys %{$self->{centreon_vmware_config}->{vsphere_server}}) {
|
||||
my $iname = lc($name);
|
||||
$self->{centreon_vmware_config}->{vsphere_server}->{$iname} = delete $self->{centreon_vmware_config}->{vsphere_server}->{$name};
|
||||
}
|
||||
|
||||
##### Load modules
|
||||
$self->load_module(@load_modules);
|
||||
|
||||
$self->{vsan_enabled} = 0;
|
||||
eval {
|
||||
centreon::vmware::common::load_vsanmgmt_binding_files(
|
||||
path => $self->{centreon_vmware_config}->{vsan_sdk_path},
|
||||
files => ['VIM25VsanmgmtStub.pm', 'VIM25VsanmgmtRuntime.pm'],
|
||||
);
|
||||
$self->{vsan_enabled} = 1;
|
||||
};
|
||||
|
||||
##### credstore check #####
|
||||
if (defined($self->{centreon_vmware_config}->{credstore_use}) && defined($self->{centreon_vmware_config}->{credstore_file}) &&
|
||||
$self->{centreon_vmware_config}->{credstore_use} == 1 && -e "$self->{centreon_vmware_config}->{credstore_file}") {
|
||||
eval 'require VMware::VICredStore';
|
||||
if ($@) {
|
||||
$self->{logger}->writeLogError("Could not load module VMware::VICredStore");
|
||||
exit(1);
|
||||
}
|
||||
require VMware::VICredStore;
|
||||
|
||||
if (VMware::VICredStore::init(filename => $self->{centreon_vmware_config}->{credstore_file}) == 0) {
|
||||
$self->{logger}->writeLogError("Credstore init failed: $@");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
###
|
||||
# Get password
|
||||
###
|
||||
foreach (keys %{$self->{centreon_vmware_config}->{vsphere_server}}) {
|
||||
my $lpassword = VMware::VICredStore::get_password(server => $_, username => $self->{centreon_vmware_config}->{vsphere_server}->{$_}->{username});
|
||||
if (!defined($lpassword)) {
|
||||
$self->{logger}->writeLogError("Can't get password for couple host='" . $_ . "', username='" . $self->{centreon_vmware_config}->{vsphere_server}->{$_}->{username} . "' : $@");
|
||||
exit(1);
|
||||
}
|
||||
$self->{centreon_vmware_config}->{vsphere_server}->{$_}->{password} = $lpassword;
|
||||
}
|
||||
}
|
||||
|
||||
$self->set_signal_handlers;
|
||||
}
|
||||
|
||||
sub set_signal_handlers {
|
||||
my $self = shift;
|
||||
|
||||
$SIG{TERM} = \&class_handle_TERM;
|
||||
$handlers{TERM}->{$self} = sub { $self->handle_TERM() };
|
||||
$SIG{HUP} = \&class_handle_HUP;
|
||||
$handlers{HUP}->{$self} = sub { $self->handle_HUP() };
|
||||
$SIG{CHLD} = \&class_handle_CHLD;
|
||||
$handlers{CHLD}->{$self} = sub { $self->handle_CHLD() };
|
||||
}
|
||||
|
||||
sub class_handle_TERM {
|
||||
foreach (keys %{$handlers{TERM}}) {
|
||||
&{$handlers{TERM}->{$_}}();
|
||||
}
|
||||
}
|
||||
|
||||
sub class_handle_HUP {
|
||||
foreach (keys %{$handlers{HUP}}) {
|
||||
&{$handlers{HUP}->{$_}}();
|
||||
}
|
||||
}
|
||||
|
||||
sub class_handle_CHLD {
|
||||
foreach (keys %{$handlers{CHLD}}) {
|
||||
&{$handlers{CHLD}->{$_}}();
|
||||
}
|
||||
}
|
||||
|
||||
sub handle_TERM {
|
||||
my $self = shift;
|
||||
$self->{logger}->writeLogInfo("$$ Receiving order to stop...");
|
||||
$self->{stop} = 1;
|
||||
|
||||
foreach (keys %{$self->{childs_vpshere_pid}}) {
|
||||
kill('TERM', $_);
|
||||
$self->{logger}->writeLogInfo("Send -TERM signal to '" . $self->{childs_vpshere_pid}->{$_} . "' process..");
|
||||
}
|
||||
}
|
||||
|
||||
sub handle_HUP {
|
||||
my $self = shift;
|
||||
$self->{logger}->writeLogInfo("$$ Receiving order to reload...");
|
||||
# TODO
|
||||
}
|
||||
|
||||
sub handle_CHLD {
|
||||
my $self = shift;
|
||||
my $child_pid;
|
||||
|
||||
while (($child_pid = waitpid(-1, &WNOHANG)) > 0) {
|
||||
$self->{return_child}{$child_pid} = {status => 1, rtime => time()};
|
||||
}
|
||||
|
||||
$SIG{CHLD} = \&class_handle_CHLD;
|
||||
}
|
||||
|
||||
sub load_module {
|
||||
my $self = shift;
|
||||
|
||||
for (@_) {
|
||||
(my $file = "$_.pm") =~ s{::}{/}g;
|
||||
require $file;
|
||||
my $obj = $_->new(logger => $self->{logger}, case_insensitive => $self->{centreon_vmware_config}->{case_insensitive});
|
||||
$self->{modules_registry}->{ $obj->getCommandName() } = $obj;
|
||||
}
|
||||
}
|
||||
|
||||
sub verify_child_vsphere {
|
||||
my $self = shift;
|
||||
|
||||
# Some dead process. need to relaunch it
|
||||
foreach (keys %{$self->{return_child}}) {
|
||||
delete $self->{return_child}->{$_};
|
||||
|
||||
if (defined($self->{childs_vpshere_pid}->{$_})) {
|
||||
if ($self->{stop} == 0) {
|
||||
my $name = $self->{childs_vpshere_pid}->{$_};
|
||||
$self->{logger}->writeLogError("Sub-process for '" . $self->{childs_vpshere_pid}->{$_} . "'???!! we relaunch it!!!");
|
||||
|
||||
if ($self->{centreon_vmware_config}->{vsphere_server}->{$self->{childs_vpshere_pid}->{$_}}->{dynamic} == 0) {
|
||||
# Can have the same pid (so we delete before)
|
||||
delete $self->{childs_vpshere_pid}->{$_};
|
||||
$self->create_vsphere_child(vsphere_name => $name, dynamic => 0);
|
||||
} else {
|
||||
$self->{logger}->writeLogError("Sub-process for '" . $self->{childs_vpshere_pid}->{$_} . "' is dead. But we don't relaunch it (dynamic sub-process)");
|
||||
delete $self->{centreon_vmware_config}->{vsphere_server}->{$self->{childs_vpshere_pid}->{$_}};
|
||||
delete $self->{childs_vpshere_pid}->{$_};
|
||||
}
|
||||
} else {
|
||||
$self->{logger}->writeLogInfo("Sub-process for '" . $self->{childs_vpshere_pid}->{$_} . "' dead ???!!");
|
||||
$self->{centreon_vmware_config}->{vsphere_server}->{$self->{childs_vpshere_pid}->{$_}}->{running} = 0;
|
||||
delete $self->{childs_vpshere_pid}->{$_};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my $count = 0;
|
||||
foreach (keys %{$self->{centreon_vmware_config}->{vsphere_server}}) {
|
||||
if ($self->{centreon_vmware_config}->{vsphere_server}->{$_}->{running} == 1) {
|
||||
$count++;
|
||||
}
|
||||
if ($self->{centreon_vmware_config}->{vsphere_server}->{$_}->{dynamic} == 1 &&
|
||||
time() - $self->{centreon_vmware_config}->{dynamic_timeout_kill} > $self->{centreon_vmware_config}->{vsphere_server}->{$_}->{last_request}) {
|
||||
$self->{logger}->writeLogError("Send TERM signal for process '" . $_ . "': too many times without requests. We clean it.");
|
||||
kill('TERM', $self->{centreon_vmware_config}->{vsphere_server}->{$_}->{pid});
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
sub waiting_ready {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return 1 if ($self->{centreon_vmware_config}->{vsphere_server}->{$options{container}}->{ready} == 1);
|
||||
|
||||
# Need to check if we need to relaunch (maybe it can have a problem)
|
||||
$self->check_childs();
|
||||
|
||||
my $time = time();
|
||||
# We wait 10 seconds
|
||||
while ($self->{centreon_vmware_config}->{vsphere_server}->{$options{container}}->{ready} == 0 &&
|
||||
time() - $time < 10) {
|
||||
zmq_poll($self->{poll}, 5000);
|
||||
}
|
||||
|
||||
if ($self->{centreon_vmware_config}->{vsphere_server}->{$options{container}}->{ready} == 0) {
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "connector still not ready.");
|
||||
centreon::vmware::common::response(token => 'RESPSERVER', endpoint => $frontend, identity => $options{identity});
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub request_dynamic {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (!defined($options{result}->{vsphere_username}) || $options{result}->{vsphere_username} eq '' ||
|
||||
!defined($options{result}->{vsphere_password}) || $options{result}->{vsphere_password} eq '') {
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "Please set vsphere username or password");
|
||||
centreon::vmware::common::response(token => 'RESPSERVER', endpoint => $frontend, identity => $options{identity});
|
||||
return ;
|
||||
}
|
||||
|
||||
my $container = md5_hex($options{result}->{vsphere_address} . $options{result}->{vsphere_username} . $options{result}->{vsphere_password});
|
||||
# Need to create fork
|
||||
if (!defined($self->{centreon_vmware_config}->{vsphere_server}->{$container})) {
|
||||
$self->{centreon_vmware_config}->{vsphere_server}->{$container} = {
|
||||
url => 'https://' . $options{result}->{vsphere_address} . '/sdk',
|
||||
username => $options{result}->{vsphere_username},
|
||||
password => $options{result}->{vsphere_password},
|
||||
last_request => time()
|
||||
};
|
||||
$self->{logger}->writeLogError(
|
||||
sprintf(
|
||||
"Dynamic creation: identity = %s [address: %s] [username: %s] [password: %s]",
|
||||
$container, $options{result}->{vsphere_address}, $options{result}->{vsphere_username}, $options{result}->{vsphere_password}
|
||||
)
|
||||
);
|
||||
$centreon_vmware->create_vsphere_child(vsphere_name => $container, dynamic => 1);
|
||||
}
|
||||
|
||||
return if ($self->waiting_ready(
|
||||
container => $container, manager => $options{manager},
|
||||
identity => $options{identity}) == 0);
|
||||
|
||||
$self->{centreon_vmware_config}->{vsphere_server}->{$container}->{last_request} = time();
|
||||
|
||||
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
|
||||
my $msg = zmq_msg_init_data("server-" . $container);
|
||||
zmq_msg_send($msg, $frontend, $flag);
|
||||
zmq_msg_close($msg);
|
||||
$msg = zmq_msg_init_data('REQCLIENT ' . $options{data});
|
||||
zmq_msg_send($msg, $frontend, ZMQ_NOBLOCK);
|
||||
zmq_msg_close($msg);
|
||||
}
|
||||
|
||||
sub request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
# Decode json
|
||||
my $result;
|
||||
eval {
|
||||
$result = JSON::XS->new->utf8->decode($options{data});
|
||||
};
|
||||
if ($@) {
|
||||
centreon::vmware::common::set_response(code => 1, short_message => "Cannot decode json result: $@");
|
||||
centreon::vmware::common::response(token => 'RESPSERVER', endpoint => $frontend, identity => $options{identity});
|
||||
return ;
|
||||
}
|
||||
if ($result->{command} eq 'stats') {
|
||||
centreon::vmware::common::stats_info(counters => $self->{counter_stats});
|
||||
centreon::vmware::common::response(token => 'RESPSERVER', endpoint => $frontend, identity => $options{identity});
|
||||
return ;
|
||||
}
|
||||
if (!defined($self->{modules_registry}->{ $result->{command} })) {
|
||||
centreon::vmware::common::set_response(code => 1, short_message => "Unknown method name '$result->{command}'");
|
||||
centreon::vmware::common::response(token => 'RESPSERVER', endpoint => $frontend, identity => $options{identity});
|
||||
return ;
|
||||
}
|
||||
if ($self->{modules_registry}->{ $result->{command} }->checkArgs(
|
||||
manager => $options{manager},
|
||||
arguments => $result)) {
|
||||
centreon::vmware::common::response(token => 'RESPSERVER', endpoint => $frontend, identity => $options{identity});
|
||||
return ;
|
||||
}
|
||||
|
||||
# Mode dynamic
|
||||
if (defined($result->{vsphere_address}) && $result->{vsphere_address} ne '') {
|
||||
$self->request_dynamic(result => $result, %options);
|
||||
return ;
|
||||
}
|
||||
|
||||
$result->{container} = lc($result->{container});
|
||||
if (!defined($self->{centreon_vmware_config}->{vsphere_server}->{ $result->{container} })) {
|
||||
centreon::vmware::common::set_response(code => 1, short_message => "Unknown container name '$result->{container}'");
|
||||
centreon::vmware::common::response(token => 'RESPSERVER', endpoint => $frontend, identity => $options{identity});
|
||||
return ;
|
||||
}
|
||||
|
||||
return if ($self->waiting_ready(
|
||||
container => $result->{container}, manager => $options{manager},
|
||||
identity => $options{identity}) == 0);
|
||||
|
||||
$self->{counter_stats}->{ $result->{container} }++;
|
||||
|
||||
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
|
||||
my $msg = zmq_msg_init_data('server-' . $result->{container});
|
||||
zmq_msg_send($msg, $frontend, $flag);
|
||||
zmq_msg_close($msg);
|
||||
$msg = zmq_msg_init_data('REQCLIENT ' . $options{data});
|
||||
zmq_msg_send($msg, $frontend, ZMQ_NOBLOCK);
|
||||
zmq_msg_close($msg);
|
||||
}
|
||||
|
||||
sub repserver {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
# Decode json
|
||||
my $result;
|
||||
eval {
|
||||
$result = JSON::XS->new->utf8->decode($options{data});
|
||||
};
|
||||
if ($@) {
|
||||
$self->{logger}->writeLogError("Cannot decode JSON: $@ (options{data}");
|
||||
return ;
|
||||
}
|
||||
|
||||
$result->{identity} =~ /^client-(.*)$/;
|
||||
my $identity = 'client-' . pack('H*', $1);
|
||||
|
||||
centreon::vmware::common::response(
|
||||
token => 'RESPSERVER', endpoint => $frontend,
|
||||
identity => $identity, force_response => $options{data}
|
||||
);
|
||||
}
|
||||
|
||||
sub router_event {
|
||||
while (1) {
|
||||
# Process all parts of the message
|
||||
my $msg = zmq_msg_init();
|
||||
zmq_msg_recv($msg, $frontend, ZMQ_DONTWAIT);
|
||||
my $identity = zmq_msg_data($msg);
|
||||
zmq_msg_close($msg);
|
||||
|
||||
$msg = zmq_msg_init();
|
||||
zmq_msg_recv($msg, $frontend, ZMQ_DONTWAIT);
|
||||
my $data = zmq_msg_data($msg);
|
||||
zmq_msg_close($msg);
|
||||
|
||||
centreon::vmware::common::init_response();
|
||||
if ($centreon_vmware->{stop} != 0) {
|
||||
# We quit so we say we're leaving ;)
|
||||
centreon::vmware::common::set_response(code => -1, short_message => 'Daemon is restarting/stopping...');
|
||||
centreon::vmware::common::response(token => 'RESPSERVER', endpoint => $frontend, identity => $identity);
|
||||
} elsif ($data =~ /^REQCLIENT\s+(.*)$/msi) {
|
||||
$centreon_vmware->request(identity => $identity, data => $1);
|
||||
} elsif ($data =~ /^RESPSERVER2\s+(.*)$/msi) {
|
||||
$centreon_vmware->repserver(data => $1);
|
||||
} elsif ($data =~ /^READY/msi) {
|
||||
$identity =~ /server-(.*)/;
|
||||
$centreon_vmware->{centreon_vmware_config}->{vsphere_server}->{$1}->{ready} = 1;
|
||||
}
|
||||
|
||||
centreon::vmware::common::free_response();
|
||||
my $more = zmq_getsockopt($frontend, ZMQ_RCVMORE);
|
||||
last unless $more;
|
||||
}
|
||||
}
|
||||
|
||||
sub check_childs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $count = $self->verify_child_vsphere();
|
||||
if ($self->{stop} == 1) {
|
||||
# No childs
|
||||
if ($count == 0) {
|
||||
$self->{logger}->writeLogInfo("Quit main process");
|
||||
zmq_close($frontend);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub create_vsphere_child {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{whoaim} = $options{vsphere_name};
|
||||
$self->{centreon_vmware_config}->{vsphere_server}->{$self->{whoaim}}->{running} = 0;
|
||||
$self->{centreon_vmware_config}->{vsphere_server}->{$self->{whoaim}}->{ready} = 0;
|
||||
$self->{logger}->writeLogInfo("Create vsphere sub-process for '" . $options{vsphere_name} . "'");
|
||||
|
||||
my $child_vpshere_pid = fork();
|
||||
if (!defined($child_vpshere_pid)) {
|
||||
$self->{logger}->writeLogError("Cannot fork for '" . $options{vsphere_name} . "': $!");
|
||||
return -1;
|
||||
}
|
||||
if ($child_vpshere_pid == 0) {
|
||||
my $connector = centreon::vmware::connector->new(
|
||||
name => $self->{whoaim},
|
||||
modules_registry => $self->{modules_registry},
|
||||
config => $self->{centreon_vmware_config},
|
||||
logger => $self->{logger},
|
||||
vsan_enabled => $self->{vsan_enabled}
|
||||
);
|
||||
$connector->run();
|
||||
exit(0);
|
||||
}
|
||||
$self->{childs_vpshere_pid}->{$child_vpshere_pid} = $self->{whoaim};
|
||||
$self->{centreon_vmware_config}->{vsphere_server}->{$self->{whoaim}}->{running} = 1;
|
||||
$self->{centreon_vmware_config}->{vsphere_server}->{$self->{whoaim}}->{dynamic} = $options{dynamic};
|
||||
$self->{centreon_vmware_config}->{vsphere_server}->{$self->{whoaim}}->{pid} = $child_vpshere_pid;
|
||||
}
|
||||
|
||||
sub bind_ipc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (zmq_bind($options{socket}, 'ipc://' . $options{ipc_file}) == -1) {
|
||||
$self->{logger}->writeLogError("Cannot bind ipc '$options{ipc_file}': $!");
|
||||
# try create dir
|
||||
$self->{logger}->writeLogError("Maybe directory does not exist. Attempting to create it!!!");
|
||||
if (!mkdir(dirname($options{ipc_file}))) {
|
||||
zmq_close($options{socket});
|
||||
exit(1);
|
||||
}
|
||||
if (zmq_bind($options{socket}, 'ipc://' . $options{ipc_file}) == -1) {
|
||||
zmq_close($options{socket});
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
$centreon_vmware = shift;
|
||||
|
||||
$centreon_vmware->SUPER::run();
|
||||
$centreon_vmware->{logger}->redirect_output();
|
||||
|
||||
$centreon_vmware->{logger}->writeLogDebug("centreon_vmware launched....");
|
||||
$centreon_vmware->{logger}->writeLogDebug("PID: $$");
|
||||
|
||||
my $context = zmq_init();
|
||||
$frontend = zmq_socket($context, ZMQ_ROUTER);
|
||||
if (!defined($frontend)) {
|
||||
$centreon_vmware->{logger}->writeLogError("Can't setup server: $!");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
zmq_setsockopt($frontend, ZMQ_LINGER, 0); # we discard
|
||||
zmq_bind($frontend, 'tcp://' . $centreon_vmware->{centreon_vmware_config}->{bind} . ':' . $centreon_vmware->{centreon_vmware_config}->{port});
|
||||
$centreon_vmware->bind_ipc(socket => $frontend, ipc_file => $centreon_vmware->{centreon_vmware_config}->{ipc_file});
|
||||
|
||||
foreach (keys %{$centreon_vmware->{centreon_vmware_config}->{vsphere_server}}) {
|
||||
$centreon_vmware->{counter_stats}->{$_} = 0;
|
||||
$centreon_vmware->create_vsphere_child(vsphere_name => $_, dynamic => 0);
|
||||
}
|
||||
|
||||
$centreon_vmware->{logger}->writeLogInfo("[Server accepting clients]");
|
||||
|
||||
# Initialize poll set
|
||||
$centreon_vmware->{poll} = [
|
||||
{
|
||||
socket => $frontend,
|
||||
events => ZMQ_POLLIN,
|
||||
callback => \&router_event
|
||||
}
|
||||
];
|
||||
|
||||
# Switch messages between sockets
|
||||
while (1) {
|
||||
$centreon_vmware->check_childs();
|
||||
zmq_poll($centreon_vmware->{poll}, 5000);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
|
@ -0,0 +1,268 @@
|
|||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package centreon::vmware::cisTags;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::http::http;
|
||||
use JSON::XS;
|
||||
|
||||
# https://developer.vmware.com/apis/vsphere-automation/v7.0U2/cis/
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = {};
|
||||
bless $self, $class;
|
||||
|
||||
$self->{is_error} = 1;
|
||||
$self->{error} = 'configuration missing';
|
||||
$self->{is_logged} = 0;
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub json_decode {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $decoded;
|
||||
eval {
|
||||
$decoded = JSON::XS->new->utf8->decode($options{content});
|
||||
};
|
||||
if ($@) {
|
||||
$self->{is_error} = 1;
|
||||
$self->{error} = "cannot decode json response: $@";
|
||||
return undef;
|
||||
}
|
||||
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
sub error {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return $self->{error};
|
||||
}
|
||||
|
||||
sub configuration {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (('url', 'username', 'password')) {
|
||||
if (!defined($options{$_}) ||
|
||||
$options{$_} eq '') {
|
||||
$self->{error} = $_ . ' configuration missing';
|
||||
return 1;
|
||||
}
|
||||
|
||||
$self->{$_} = $options{$_};
|
||||
}
|
||||
|
||||
if ($self->{url} =~ /^((?:http|https):\/\/.*?)\//) {
|
||||
$self->{url} = $1;
|
||||
}
|
||||
|
||||
$self->{http_backend} = defined($options{backend}) ? $options{backend} : 'curl';
|
||||
|
||||
$self->{curl_opts} = ['CURLOPT_SSL_VERIFYPEER => 0', 'CURLOPT_POSTREDIR => CURL_REDIR_POST_ALL'];
|
||||
my $curl_opts = [];
|
||||
if (defined($options{curlopts})) {
|
||||
foreach (keys %{$options{curlopts}}) {
|
||||
push @{$curl_opts}, $_ . ' => ' . $options{curlopts}->{$_};
|
||||
}
|
||||
}
|
||||
if (scalar(@$curl_opts) > 0) {
|
||||
$self->{curl_opts} = $curl_opts;
|
||||
}
|
||||
|
||||
$self->{http} = centreon::vmware::http::http->new(logger => $options{logger});
|
||||
$self->{is_error} = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub authenticate {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my ($code, $content) = $self->{http}->request(
|
||||
http_backend => $self->{http_backend},
|
||||
method => 'POST',
|
||||
query_form_post => '',
|
||||
hostname => '',
|
||||
full_url => $self->{url} . '/rest/com/vmware/cis/session',
|
||||
header => [
|
||||
'Accept-Type: application/json; charset=utf-8',
|
||||
'Content-Type: application/json; charset=utf-8',
|
||||
],
|
||||
curl_opt => $self->{curl_opts},
|
||||
credentials => 1,
|
||||
basic => 1,
|
||||
username => $self->{username},
|
||||
password => $self->{password},
|
||||
warning_status => '',
|
||||
unknown_status => '',
|
||||
critical_status => ''
|
||||
);
|
||||
if ($code) {
|
||||
$self->{is_error} = 1;
|
||||
$self->{error} = 'http request error';
|
||||
return undef;
|
||||
}
|
||||
if ($self->{http}->get_code() < 200 || $self->{http}->get_code() >= 300) {
|
||||
$self->{is_error} = 1;
|
||||
$self->{error} = "Login error [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']";
|
||||
return undef;
|
||||
}
|
||||
|
||||
my $decoded = $self->json_decode(content => $content);
|
||||
return if (!defined($decoded));
|
||||
|
||||
my $token = defined($decoded->{value}) ? $decoded->{value} : undef;
|
||||
if (!defined($token)) {
|
||||
$self->{is_error} = 1;
|
||||
$self->{error} = 'authenticate issue - cannot get token';
|
||||
return undef;
|
||||
}
|
||||
|
||||
$self->{token} = $token;
|
||||
$self->{is_logged} = 1;
|
||||
}
|
||||
|
||||
sub request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (!defined($self->{url})) {
|
||||
$self->{is_error} = 1;
|
||||
$self->{error} = 'configuration missing';
|
||||
return 1;
|
||||
}
|
||||
|
||||
$self->{is_error} = 0;
|
||||
if ($self->{is_logged} == 0) {
|
||||
$self->authenticate();
|
||||
}
|
||||
|
||||
return 1 if ($self->{is_logged} == 0);
|
||||
|
||||
my ($code, $content) = $self->{http}->request(
|
||||
http_backend => $self->{http_backend},
|
||||
method => $options{method},
|
||||
hostname => '',
|
||||
full_url => $self->{url} . $options{endpoint},
|
||||
query_form_post => $options{query_form_post},
|
||||
get_param => $options{get_param},
|
||||
header => [
|
||||
'Accept-Type: application/json; charset=utf-8',
|
||||
'Content-Type: application/json; charset=utf-8',
|
||||
'vmware-api-session-id: ' . $self->{token}
|
||||
],
|
||||
curl_opt => $self->{curl_opts},
|
||||
warning_status => '',
|
||||
unknown_status => '',
|
||||
critical_status => ''
|
||||
);
|
||||
|
||||
my $decoded = $self->json_decode(content => $content);
|
||||
|
||||
# code 403 means forbidden (token not good maybe)
|
||||
if ($self->{http}->get_code() < 200 || $self->{http}->get_code() >= 300) {
|
||||
$self->{token} = undef;
|
||||
$self->{is_logged} = 0;
|
||||
$self->{is_error} = 1;
|
||||
$self->{error} = $content;
|
||||
$self->{error} = $decoded->{value}->[0]->{default_message} if (defined($decoded) && defined($decoded->{value}->[0]->{default_message}));
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1 if (!defined($decoded));
|
||||
|
||||
return (0, $decoded);
|
||||
}
|
||||
|
||||
sub tagsByResource {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my ($code, $tag_ids) = $self->request(
|
||||
method => 'GET',
|
||||
endpoint => '/rest/com/vmware/cis/tagging/tag'
|
||||
);
|
||||
return $code if ($code);
|
||||
|
||||
my $tags = {};
|
||||
my $result = { esx => {} , vm => {} };
|
||||
if (defined($tag_ids->{value})) {
|
||||
my $json_req = { tag_ids => [] };
|
||||
foreach my $tag_id (@{$tag_ids->{value}}) {
|
||||
my ($code, $tag_detail) = $self->request(
|
||||
method => 'GET',
|
||||
endpoint => '/rest/com/vmware/cis/tagging/tag/id:' . $tag_id
|
||||
);
|
||||
return $code if ($code);
|
||||
|
||||
push @{$json_req->{tag_ids}}, $tag_id;
|
||||
$tags->{ $tag_id } = { name => $tag_detail->{value}->{name}, description => $tag_detail->{value}->{description} };
|
||||
}
|
||||
|
||||
my $data;
|
||||
eval {
|
||||
$data = encode_json($json_req);
|
||||
};
|
||||
if ($@) {
|
||||
$self->{is_error} = 1;
|
||||
$self->{error} = "cannot encode json request: $@";
|
||||
return undef;
|
||||
}
|
||||
|
||||
my ($code, $tags_assoc) = $self->request(
|
||||
method => 'POST',
|
||||
endpoint => '/rest/com/vmware/cis/tagging/tag-association',
|
||||
get_param => ['~action=list-attached-objects-on-tags'],
|
||||
query_form_post => $data
|
||||
);
|
||||
return $code if ($code);
|
||||
|
||||
if (defined($tags_assoc->{value})) {
|
||||
foreach my $entry (@{$tags_assoc->{value}}) {
|
||||
foreach my $entity (@{$entry->{object_ids}}) {
|
||||
if ($entity->{type} eq 'VirtualMachine') {
|
||||
$result->{vm}->{ $entity->{id} } = [] if (!defined($result->{vm}->{ $entity->{id} }));
|
||||
push @{$result->{vm}->{ $entity->{id} }}, $tags->{ $entry->{tag_id} };
|
||||
} elsif ($entity->{type} eq 'HostSystem') {
|
||||
$result->{esx}->{ $entity->{id} } = [] if (!defined($result->{esx}->{ $entity->{id} }));
|
||||
push @{$result->{esx}->{ $entity->{id} }}, $tags->{ $entry->{tag_id} };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (0, $result);
|
||||
}
|
||||
|
||||
sub DESTROY {
|
||||
my ($self) = @_;
|
||||
|
||||
if ($self->{is_logged} == 1) {
|
||||
$self->request(
|
||||
method => 'DELETE',
|
||||
endpoint => '/rest/com/vmware/cis/session'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,77 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdalarmdatacenter;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'alarmdatacenter';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{datacenter}) && $options{arguments}->{datacenter} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: datacenter cannot be null");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'datacenter', is_regexp => 'filter');
|
||||
my @properties = ('name', 'triggeredAlarmState');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'Datacenter', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $data = {};
|
||||
foreach my $datacenter_view (@$result) {
|
||||
$data->{$datacenter_view->{mo_ref}->{value}} = { name => $datacenter_view->name, red => 0, yellow => 0, alarms => {} };
|
||||
next if (!defined($datacenter_view->triggeredAlarmState));
|
||||
foreach (@{$datacenter_view->triggeredAlarmState}) {
|
||||
next if ($_->overallStatus->val !~ /(red|yellow)/i);
|
||||
|
||||
my $entity = centreon::vmware::common::get_view($self->{connector}, $_->entity, ['name']);
|
||||
my $alarm = centreon::vmware::common::get_view($self->{connector}, $_->alarm, ['info']);
|
||||
|
||||
$data->{$datacenter_view->{mo_ref}->{value}}->{alarms}->{$_->key} = { type => $_->entity->type, entity_name => $entity->name,
|
||||
time => $_->time, name => $alarm->info->name,
|
||||
description => $alarm->info->description,
|
||||
status => $_->overallStatus->val
|
||||
};
|
||||
$data->{$datacenter_view->{mo_ref}->{value}}->{$_->overallStatus->val}++;
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,78 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdalarmhost;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'alarmhost';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter');
|
||||
my @properties = ('name', 'triggeredAlarmState');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $data = {};
|
||||
foreach my $host_view (@$result) {
|
||||
$data->{$host_view->{mo_ref}->{value}} = { name => $host_view->name, red => 0, yellow => 0, alarms => {} };
|
||||
next if (!defined($host_view->triggeredAlarmState));
|
||||
foreach(@{$host_view->triggeredAlarmState}) {
|
||||
next if ($_->overallStatus->val !~ /(red|yellow)/i);
|
||||
|
||||
my $entity = centreon::vmware::common::get_view($self->{connector}, $_->entity, ['name']);
|
||||
my $alarm = centreon::vmware::common::get_view($self->{connector}, $_->alarm, ['info']);
|
||||
|
||||
$data->{$host_view->{mo_ref}->{value}}->{alarms}->{$_->key} = {
|
||||
type => $_->entity->type, entity_name => $entity->name,
|
||||
time => $_->time, name => $alarm->info->name,
|
||||
description => $alarm->info->description,
|
||||
status => $_->overallStatus->val
|
||||
};
|
||||
$data->{$host_view->{mo_ref}->{value}}->{$_->overallStatus->val}++;
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,136 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdbase;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
use VMware::VIRuntime;
|
||||
use VMware::VILib;
|
||||
|
||||
my %handlers = (ALRM => {});
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = {};
|
||||
bless $self, $class;
|
||||
|
||||
$self->{logger} = $options{logger};
|
||||
$self->{global_case_insensitive} = defined($options{case_insensitive}) ? $options{case_insensitive} : 0;
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub getCommandName {
|
||||
my $self = shift;
|
||||
return $self->{commandName};
|
||||
}
|
||||
|
||||
sub set_signal_handlers {
|
||||
my $self = shift;
|
||||
|
||||
$SIG{ALRM} = \&class_handle_ALRM;
|
||||
$handlers{ALRM}->{$self} = sub { $self->handle_ALRM() };
|
||||
}
|
||||
|
||||
sub class_handle_ALRM {
|
||||
foreach (keys %{$handlers{ALRM}}) {
|
||||
&{$handlers{ALRM}->{$_}}();
|
||||
}
|
||||
}
|
||||
|
||||
sub handle_ALRM {
|
||||
my $self = shift;
|
||||
|
||||
$self->{logger}->writeLogError('Child process autokill!!');
|
||||
exit(0);
|
||||
}
|
||||
|
||||
sub is_vsan_enabled {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if ($self->{connector}->{vsan_enabled} == 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub set_connector {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{connector} = $options{connector};
|
||||
|
||||
#$self->{connector}->{session_clone} = Vim::load_session(service_url => $self->{connector}->{service_url}, session_file => '/tmp/plop.save');
|
||||
#$self->{connector}->{session_clone} = Vim->new(service_url => $self->{connector}->{service_url});
|
||||
#$self->{connector}->{session_clone}->load_session(session_file => '/tmp/plop.save');
|
||||
|
||||
$self->set_signal_handlers();
|
||||
alarm(300);
|
||||
}
|
||||
|
||||
sub initArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (keys %{$options{arguments}}) {
|
||||
$self->{$_} = $options{arguments}->{$_};
|
||||
}
|
||||
centreon::vmware::common::init_response(identity => $options{arguments}->{identity});
|
||||
|
||||
if ($self->{global_case_insensitive} == 0 && defined($self->{case_insensitive})) {
|
||||
$self->{global_case_insensitive} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
sub build_filter {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $filters = {};
|
||||
if (defined($self->{$options{search_option}}) && !defined($self->{$options{is_regexp}})) {
|
||||
if ($self->{global_case_insensitive} == 1) {
|
||||
$filters->{name} = qr/^\Q$self->{$options{search_option}}\E$/i;
|
||||
} else {
|
||||
$filters->{name} = qr/^\Q$self->{$options{search_option}}\E$/;
|
||||
}
|
||||
} elsif (!defined($self->{$options{search_option}})) {
|
||||
$filters->{name} = qr/.*/;
|
||||
} else {
|
||||
if ($self->{global_case_insensitive} == 1) {
|
||||
$filters->{name} = qr/$self->{$options{search_option}}/i;
|
||||
} else {
|
||||
$filters->{name} = qr/$self->{$options{search_option}}/;
|
||||
}
|
||||
}
|
||||
|
||||
return $filters;
|
||||
}
|
||||
|
||||
sub add_filter {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($self->{$options{search_option}}) && $self->{$options{search_option}} ne '') {
|
||||
if ($self->{global_case_insensitive} == 1) {
|
||||
$options{filters}->{$options{label}} = qr/$self->{$options{search_option}}/i;
|
||||
} else {
|
||||
$options{filters}->{$options{label}} = qr/$self->{$options{search_option}}/;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,94 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdcountvmhost;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'countvmhost';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter');
|
||||
my @properties = ('name', 'vm', 'runtime.connectionState');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
#return if (centreon::vmware::common::host_state($self->{connector}, $self->{lhost},
|
||||
# $$result[0]->{'runtime.connectionState'}->val) == 0);
|
||||
|
||||
my @vm_array = ();
|
||||
foreach my $entity_view (@$result) {
|
||||
if (defined($entity_view->vm)) {
|
||||
@vm_array = (@vm_array, @{$entity_view->vm});
|
||||
}
|
||||
}
|
||||
@properties = ('runtime.powerState');
|
||||
my $result2 = centreon::vmware::common::get_views($self->{connector}, \@vm_array, \@properties);
|
||||
return if (!defined($result2));
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
$data->{$entity_value} = { name => $entity_view->{name}, state => $entity_view->{'runtime.connectionState'}->val };
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
|
||||
my %vm_states = (poweredon => 0, poweredoff => 0, suspended => 0);
|
||||
if (defined($entity_view->vm)) {
|
||||
foreach my $vm_host (@{$entity_view->vm}) {
|
||||
foreach my $vm (@{$result2}) {
|
||||
if ($vm_host->{value} eq $vm->{mo_ref}->{value}) {
|
||||
my $power_value = lc($vm->{'runtime.powerState'}->val);
|
||||
$vm_states{$power_value}++;
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data->{$entity_value} = { %{$data->{$entity_value}}, %vm_states };
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,97 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdcpucluster;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'cpucluster';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{cluster_name}) && $options{arguments}->{cluster_name} eq '') {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => 'Argument error: cluster name cannot be null');
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{connector}->{perfcounter_speriod} > 0)) {
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'cluster_name', is_regexp => 'filter');
|
||||
my @properties = ('name');
|
||||
my $views = centreon::vmware::common::search_entities(command => $self, view_type => 'ClusterComputeResource', properties => \@properties, filter => $filters);
|
||||
return if (!defined($views));
|
||||
|
||||
my $values = centreon::vmware::common::generic_performance_values_historic(
|
||||
$self->{connector},
|
||||
$views,
|
||||
[
|
||||
{ label => 'cpu.usage.average', instances => [''] },
|
||||
{ label => 'cpu.usagemhz.average', instances => [''] }
|
||||
],
|
||||
$self->{connector}->{perfcounter_speriod},
|
||||
sampling_period => $self->{sampling_period},
|
||||
time_shift => $self->{time_shift},
|
||||
skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1
|
||||
);
|
||||
return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1);
|
||||
|
||||
my $interval_min = centreon::vmware::common::get_interval_min(
|
||||
speriod => $self->{connector}->{perfcounter_speriod},
|
||||
sampling_period => $self->{sampling_period},
|
||||
time_shift => $self->{time_shift}
|
||||
);
|
||||
|
||||
my $data = {};
|
||||
foreach my $view (@$views) {
|
||||
my $entity_value = $view->{mo_ref}->{value};
|
||||
$data->{$entity_value} = { name => $view->{name} };
|
||||
|
||||
my $total_cpu_average = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{ $self->{connector}->{perfcounter_cache}->{'cpu.usage.average'}->{key} . ':' } * 0.01));
|
||||
my $total_cpu_mhz_average = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{ $self->{connector}->{perfcounter_cache}->{'cpu.usagemhz.average'}->{key} . ':' }));
|
||||
|
||||
$data->{$entity_value}->{'interval_min'} = $interval_min;
|
||||
$data->{$entity_value}->{'cpu.usage.average'} = $total_cpu_average;
|
||||
$data->{$entity_value}->{'cpu.usagemhz.average'} = $total_cpu_mhz_average;
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,112 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdcpuhost;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'cpuhost';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{connector}->{perfcounter_speriod} > 0)) {
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter');
|
||||
my @properties = ('name', 'runtime.connectionState', 'summary.hardware.numCpuCores', 'summary.hardware.cpuMhz');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my @instances = ('*');
|
||||
my $values = centreon::vmware::common::generic_performance_values_historic(
|
||||
$self->{connector},
|
||||
$result,
|
||||
[
|
||||
{ label => 'cpu.usage.average', 'instances' => \@instances},
|
||||
{ label => 'cpu.usagemhz.average', 'instances' => \@instances}
|
||||
],
|
||||
$self->{connector}->{perfcounter_speriod},
|
||||
sampling_period => $self->{sampling_period},
|
||||
time_shift => $self->{time_shift},
|
||||
skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1
|
||||
);
|
||||
return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1);
|
||||
|
||||
my $interval_min = centreon::vmware::common::get_interval_min(
|
||||
speriod => $self->{connector}->{perfcounter_speriod},
|
||||
sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift}
|
||||
);
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
$data->{$entity_value} = { name => $entity_view->{name}, state => $entity_view->{'runtime.connectionState'}->val };
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
|
||||
my $total_cpu_average = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'cpu.usage.average'}->{'key'} . ":"} * 0.01));
|
||||
my $total_cpu_mhz_average = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'cpu.usagemhz.average'}->{'key'} . ":"}));
|
||||
|
||||
$data->{$entity_value}->{'interval_min'} = $interval_min;
|
||||
$data->{$entity_value}->{'cpu.usage.average'} = $total_cpu_average;
|
||||
$data->{$entity_value}->{'cpu.usagemhz.average'} = $total_cpu_mhz_average;
|
||||
$data->{$entity_value}->{'numCpuCores'} = $entity_view->{'summary.hardware.numCpuCores'};
|
||||
$data->{$entity_value}->{'cpuMhz'} = $entity_view->{'summary.hardware.cpuMhz'};
|
||||
$data->{$entity_value}->{'cpu'} = {};
|
||||
|
||||
foreach my $id (sort { my ($cida, $cia) = split /:/, $a;
|
||||
my ($cidb, $cib) = split /:/, $b;
|
||||
$cia = -1 if (!defined($cia) || $cia eq "");
|
||||
$cib = -1 if (!defined($cib) || $cib eq "");
|
||||
$cia <=> $cib} keys %{$values->{$entity_value}}) {
|
||||
my ($counter_id, $instance) = split /:/, $id;
|
||||
if ($instance ne "") {
|
||||
$data->{$entity_value}->{cpu}->{$instance} = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$id}) * 0.01);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,132 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdcpuvm;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'cpuvm';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: vm hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{connector}->{perfcounter_speriod} > 0)) {
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'vm_hostname', is_regexp => 'filter');
|
||||
$self->add_filter(filters => $filters, label => 'config.annotation', search_option => 'filter_description');
|
||||
$self->add_filter(filters => $filters, label => 'config.guestFullName', search_option => 'filter_os');
|
||||
$self->add_filter(filters => $filters, label => 'config.uuid', search_option => 'filter_uuid');
|
||||
|
||||
my @properties = ('name', 'runtime.connectionState', 'runtime.powerState');
|
||||
if (defined($self->{display_description})) {
|
||||
push @properties, 'config.annotation';
|
||||
}
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'VirtualMachine', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my @instances = ('*');
|
||||
my $values = centreon::vmware::common::generic_performance_values_historic(
|
||||
$self->{connector},
|
||||
$result,
|
||||
[
|
||||
{'label' => 'cpu.usage.average', 'instances' => \@instances},
|
||||
{'label' => 'cpu.usagemhz.average', 'instances' => \@instances},
|
||||
{'label' => 'cpu.ready.summation', 'instances' => \@instances}
|
||||
],
|
||||
$self->{connector}->{perfcounter_speriod},
|
||||
sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift},
|
||||
skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1
|
||||
);
|
||||
return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1);
|
||||
|
||||
my $interval_sec = $self->{connector}->{perfcounter_speriod};
|
||||
if (defined($self->{sampling_period}) && $self->{sampling_period} ne '') {
|
||||
$interval_sec = $self->{sampling_period};
|
||||
}
|
||||
my $interval_min = centreon::vmware::common::get_interval_min(
|
||||
speriod => $self->{connector}->{perfcounter_speriod},
|
||||
sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift}
|
||||
);
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
|
||||
$data->{$entity_value} = {
|
||||
name => $entity_view->{name},
|
||||
connection_state => $entity_view->{'runtime.connectionState'}->val,
|
||||
power_state => $entity_view->{'runtime.powerState'}->val,
|
||||
'config.annotation' => defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : undef,
|
||||
};
|
||||
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
next if (centreon::vmware::common::is_running(power => $entity_view->{'runtime.powerState'}->val) == 0);
|
||||
|
||||
my $total_cpu_average = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'cpu.usage.average'}->{'key'} . ":"} * 0.01));
|
||||
my $total_cpu_mhz_average = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'cpu.usagemhz.average'}->{'key'} . ":"}));
|
||||
my $total_cpu_ready = centreon::vmware::common::simplify_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'cpu.ready.summation'}->{'key'} . ":"} / ($interval_sec * 1000) * 100);
|
||||
|
||||
$data->{$entity_value}->{'cpu.usage.average'} = $total_cpu_average;
|
||||
$data->{$entity_value}->{'cpu.usagemhz.average'} = $total_cpu_mhz_average;
|
||||
$data->{$entity_value}->{'cpu_ready'} = $total_cpu_ready;
|
||||
$data->{$entity_value}->{'interval_min'} = $interval_min;
|
||||
$data->{$entity_value}->{'cpu'} = {};
|
||||
|
||||
foreach my $id (sort { my ($cida, $cia) = split /:/, $a;
|
||||
my ($cidb, $cib) = split /:/, $b;
|
||||
$cia = -1 if (!defined($cia) || $cia eq "");
|
||||
$cib = -1 if (!defined($cib) || $cib eq "");
|
||||
$cia <=> $cib} keys %{$values->{$entity_value}}) {
|
||||
my ($counter_id, $instance) = split /:/, $id;
|
||||
next if ($self->{connector}->{perfcounter_cache}->{'cpu.usagemhz.average'}->{key} != $counter_id);
|
||||
if ($instance ne "") {
|
||||
$data->{$entity_value}->{cpu}->{$instance} = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$id}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,91 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmddatastorecountvm;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'datastorecountvm';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{datastore_name}) && $options{arguments}->{datastore_name} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: datastore name cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'datastore_name', is_regexp => 'filter');
|
||||
my @properties = ('summary.name', 'vm', 'summary.accessible');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'Datastore', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my @vm_array = ();
|
||||
foreach my $entity_view (@$result) {
|
||||
if (defined($entity_view->vm)) {
|
||||
@vm_array = (@vm_array, @{$entity_view->vm});
|
||||
}
|
||||
}
|
||||
@properties = ('runtime.powerState');
|
||||
my $result2 = centreon::vmware::common::get_views($self->{connector}, \@vm_array, \@properties);
|
||||
return if (!defined($result2));
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
$data->{$entity_value} = { name => $entity_view->{'summary.name'}, accessible => $entity_view->{'summary.accessible'} };
|
||||
next if (centreon::vmware::common::is_accessible(accessible => $entity_view->{'summary.accessible'}) == 0);
|
||||
|
||||
my %vm_states = (poweredon => 0, poweredoff => 0, suspended => 0);
|
||||
if (defined($entity_view->vm)) {
|
||||
foreach my $vm_host (@{$entity_view->vm}) {
|
||||
foreach my $vm (@{$result2}) {
|
||||
if ($vm_host->{value} eq $vm->{mo_ref}->{value}) {
|
||||
my $power_value = lc($vm->{'runtime.powerState'}->val);
|
||||
$vm_states{$power_value}++;
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data->{$entity_value} = { %{$data->{$entity_value}}, %vm_states };
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,153 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmddatastorehost;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use File::Basename;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'datastorehost';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
if (defined($options{arguments}->{datastore_name}) && $options{arguments}->{datastore_name} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: datastore name cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{connector}->{perfcounter_speriod} > 0)) {
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter');
|
||||
my @properties = ('name', 'config.fileSystemVolume.mountInfo', 'runtime.connectionState');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my %uuid_list = ();
|
||||
#my %disk_name = ();
|
||||
my $query_perfs = [];
|
||||
my $ds_regexp;
|
||||
if (defined($self->{datastore_name}) && !defined($self->{filter_datastore})) {
|
||||
$ds_regexp = qr/^\Q$self->{datastore_name}\E$/;
|
||||
} elsif (!defined($self->{datastore_name})) {
|
||||
$ds_regexp = qr/.*/;
|
||||
} else {
|
||||
$ds_regexp = qr/$self->{datastore_name}/;
|
||||
}
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
$data->{$entity_value} = { name => $entity_view->{name}, state => $entity_view->{'runtime.connectionState'}->val, datastore => {} };
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
|
||||
my $instances = [];
|
||||
foreach (@{$entity_view->{'config.fileSystemVolume.mountInfo'}}) {
|
||||
if ($_->volume->isa('HostVmfsVolume')) {
|
||||
next if ($_->volume->name !~ /$ds_regexp/);
|
||||
|
||||
$uuid_list{$_->volume->uuid} = $_->volume->name;
|
||||
push @$instances, $_->volume->uuid;
|
||||
# Not need. We are on Datastore level (not LUN level)
|
||||
#foreach my $extent (@{$_->volume->extent}) {
|
||||
# $disk_name{$extent->diskName} = $_->volume->name;
|
||||
#}
|
||||
}
|
||||
if ($_->volume->isa('HostNasVolume')) {
|
||||
next if ($_->volume->name !~ /$ds_regexp/);
|
||||
|
||||
$uuid_list{basename($_->mountInfo->path)} = $_->volume->name;
|
||||
push @$instances, basename($_->mountInfo->path);
|
||||
}
|
||||
}
|
||||
|
||||
if (scalar(@$instances) > 0) {
|
||||
push @$query_perfs, {
|
||||
entity => $entity_view,
|
||||
metrics => [
|
||||
{ label => 'datastore.totalReadLatency.average', instances => $instances },
|
||||
{ label => 'datastore.totalWriteLatency.average', instances => $instances }
|
||||
]
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (scalar(@$query_perfs) == 0) {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Can't get a single datastore.");
|
||||
return ;
|
||||
}
|
||||
|
||||
# Vsphere >= 4.1
|
||||
# You get counters even if datastore is disconnect...
|
||||
my $values = centreon::vmware::common::generic_performance_values_historic($self->{connector},
|
||||
undef,
|
||||
$query_perfs,
|
||||
$self->{connector}->{perfcounter_speriod},
|
||||
sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift},
|
||||
skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1);
|
||||
return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1);
|
||||
|
||||
foreach my $entity_view (@$result) {
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
|
||||
my $checked = {};
|
||||
foreach (keys %{$values->{$entity_value}}) {
|
||||
my ($id, $uuid) = split /:/;
|
||||
next if (defined($checked->{$uuid}));
|
||||
$checked->{$uuid} = 1;
|
||||
|
||||
my $read_counter = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'datastore.totalReadLatency.average'}->{'key'} . ":" . $uuid}));
|
||||
my $write_counter = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'datastore.totalWriteLatency.average'}->{'key'} . ":" . $uuid}));
|
||||
|
||||
$data->{$entity_value}->{datastore}->{$uuid_list{$uuid}} = {
|
||||
'datastore.totalReadLatency.average' => $read_counter,
|
||||
'datastore.totalWriteLatency.average' => $write_counter,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,88 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmddatastoreio;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'datastoreio';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{datastore_name}) && $options{arguments}->{datastore_name} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: datastore name cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{connector}->{perfcounter_speriod} > 0)) {
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'datastore_name', is_regexp => 'filter');
|
||||
my @properties = ('summary.name', 'summary.accessible');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'Datastore', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $values = centreon::vmware::common::generic_performance_values_historic($self->{connector},
|
||||
$result,
|
||||
[{'label' => 'datastore.read.average', 'instances' => ['']},
|
||||
{'label' => 'datastore.write.average', 'instances' => ['']}],
|
||||
$self->{connector}->{perfcounter_speriod},
|
||||
sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift},
|
||||
skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1);
|
||||
return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1);
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
|
||||
$data->{$entity_value} = { name => $entity_view->{'summary.name'}, accessible => $entity_view->{'summary.accessible'} };
|
||||
next if (centreon::vmware::common::is_accessible(accessible => $entity_view->{'summary.accessible'}) == 0);
|
||||
|
||||
# in KBps
|
||||
my $read_counter = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'datastore.read.average'}->{'key'} . ":"})) * 1024;
|
||||
my $write_counter = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'datastore.write.average'}->{'key'} . ":"})) * 1024;
|
||||
|
||||
$data->{$entity_value}->{'datastore.read.average'} = $read_counter;
|
||||
$data->{$entity_value}->{'datastore.write.average'} = $write_counter;
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,256 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmddatastoreiops;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'datastoreiops';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{datastore_name}) && $options{arguments}->{datastore_name} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: datastore name cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{connector}->{perfcounter_speriod} > 0)) {
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'datastore_name', is_regexp => 'filter');
|
||||
my @properties = ('summary.accessible', 'summary.name', 'summary.type', 'vm', 'info');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'Datastore', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $ds_vsan = {};
|
||||
|
||||
my $data = {};
|
||||
#my %uuid_list = ();
|
||||
my %disk_name = ();
|
||||
my %datastore_lun = ();
|
||||
my $ds_checked = 0;
|
||||
foreach (@$result) {
|
||||
$data->{$_->{'summary.name'}} = { name => $_->{'summary.name'}, accessible => $_->{'summary.accessible'}, type => $_->{'summary.type'} };
|
||||
next if (centreon::vmware::common::is_accessible(accessible => $_->{'summary.accessible'}) == 0);
|
||||
|
||||
if ($_->{'summary.type'} eq 'vsan') {
|
||||
$ds_vsan->{$_->{mo_ref}->{value}} = $_->{'summary.name'};
|
||||
$ds_checked = 1;
|
||||
}
|
||||
if ($_->info->isa('VmfsDatastoreInfo')) {
|
||||
#$uuid_list{$_->volume->uuid} = $_->volume->name;
|
||||
# Not need. We are on Datastore level (not LUN level)
|
||||
$ds_checked = 1;
|
||||
foreach my $extent (@{$_->info->vmfs->extent}) {
|
||||
$disk_name{$extent->diskName} = $_->info->vmfs->name;
|
||||
if (!defined($datastore_lun{$_->info->vmfs->name})) {
|
||||
%{$datastore_lun{$_->info->vmfs->name}} = ('disk.numberRead.summation' => 0, 'disk.numberWrite.summation' => 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
#if ($_->info->isa('NasDatastoreInfo')) {
|
||||
# Zero disk Info
|
||||
#}
|
||||
}
|
||||
|
||||
if ($ds_checked == 0) {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "No Vmfs datastore(s) checked. Cannot get iops from Nas datastore(s)");
|
||||
return ;
|
||||
}
|
||||
|
||||
my @vm_array = ();
|
||||
my %added_vm = ();
|
||||
foreach my $entity_view (@$result) {
|
||||
if (defined($entity_view->vm)) {
|
||||
foreach (@{$entity_view->vm}) {
|
||||
next if (defined($added_vm{$_->{value}}));
|
||||
push @vm_array, $_;
|
||||
$added_vm{$_->{value}} = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (scalar(@vm_array) == 0) {
|
||||
centreon::vmware::common::set_response(code => 200, short_message => "No virtual machines on the datastore");
|
||||
return ;
|
||||
}
|
||||
|
||||
@properties = ('name', 'summary.config.instanceUuid', 'runtime.connectionState', 'runtime.powerState');
|
||||
my $result2 = centreon::vmware::common::get_views($self->{connector}, \@vm_array, \@properties);
|
||||
return if (!defined($result2));
|
||||
|
||||
# Remove disconnected or not running vm
|
||||
my ($moref_vm, $uuid_vm) = ({}, {});
|
||||
for(my $i = $#{$result2}; $i >= 0; --$i) {
|
||||
if (!centreon::vmware::common::is_connected(state => $result2->[$i]->{'runtime.connectionState'}->val) ||
|
||||
!centreon::vmware::common::is_running(power => $result2->[$i]->{'runtime.powerState'}->val)) {
|
||||
splice @$result2, $i, 1;
|
||||
next;
|
||||
}
|
||||
|
||||
$uuid_vm->{$result2->[$i]->{'summary.config.instanceUuid'}} = $result2->[$i]->{mo_ref}->{value};
|
||||
$moref_vm->{$result2->[$i]->{mo_ref}->{value}} = $result2->[$i]->{name};
|
||||
}
|
||||
|
||||
if (scalar(@{$result2}) == 0) {
|
||||
centreon::vmware::common::set_response(code => 200, short_message => "No active virtual machines on the datastore");
|
||||
return ;
|
||||
}
|
||||
|
||||
my $interval_sec = $self->{connector}->{perfcounter_speriod};
|
||||
if (defined($self->{sampling_period}) && $self->{sampling_period} ne '') {
|
||||
$interval_sec = $self->{sampling_period};
|
||||
}
|
||||
|
||||
# VSAN part
|
||||
if ($self->is_vsan_enabled() && scalar(keys(%$ds_vsan)) > 0) {
|
||||
my $vsan_performance_mgr = centreon::vmware::common::vsan_create_mo_view(
|
||||
vsan_vim => $self->{connector}->{vsan_vim},
|
||||
type => 'VsanPerformanceManager',
|
||||
value => 'vsan-performance-manager',
|
||||
);
|
||||
my $cluster_views = centreon::vmware::common::search_entities(command => $self, view_type => 'ComputeResource', properties => ['name', 'datastore'], filter => undef);
|
||||
my $clusters = {};
|
||||
foreach my $cluster_view (@$cluster_views) {
|
||||
$clusters->{$cluster_view->{name}} = {};
|
||||
foreach (@{$cluster_view->{datastore}}) {
|
||||
if (defined($ds_vsan->{$_->{value}})) {
|
||||
$clusters->{$cluster_view->{name}}->{ds_vsan} = $ds_vsan->{$_->{value}};
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
next if (!defined($clusters->{$cluster_view->{name}}->{ds_vsan}));
|
||||
my $result = centreon::vmware::common::vsan_get_performances(
|
||||
vsan_performance_mgr => $vsan_performance_mgr,
|
||||
cluster => $cluster_view,
|
||||
entityRefId => 'virtual-machine:*',
|
||||
labels => ['iopsRead', 'iopsWrite'],
|
||||
interval => $interval_sec,
|
||||
time_shift => $self->{time_shift}
|
||||
);
|
||||
|
||||
$datastore_lun{ $clusters->{$cluster_view->{name}}->{ds_vsan} } = {
|
||||
'disk.numberRead.summation' => 0,
|
||||
'disk.numberWrite.summation' => 0,
|
||||
};
|
||||
# we recreate format: vm-{movalue}_disk.numberWrite.summation
|
||||
foreach (keys %$result) {
|
||||
next if (! /virtual-machine:(.*)/);
|
||||
next if (!defined($uuid_vm->{$1}));
|
||||
my $moref = $uuid_vm->{$1};
|
||||
$datastore_lun{ $clusters->{$cluster_view->{name}}->{ds_vsan} }->{$moref . '_disk.numberRead.summation'} = $result->{$_}->{iopsRead};
|
||||
$datastore_lun{ $clusters->{$cluster_view->{name}}->{ds_vsan} }->{$moref . '_disk.numberWrite.summation'} = $result->{$_}->{iopsWrite};
|
||||
$datastore_lun{ $clusters->{$cluster_view->{name}}->{ds_vsan} }->{'disk.numberRead.summation'} += $result->{$_}->{iopsRead};
|
||||
$datastore_lun{ $clusters->{$cluster_view->{name}}->{ds_vsan} }->{'disk.numberWrite.summation'} += $result->{$_}->{iopsWrite};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Vsphere >= 4.1
|
||||
my $values = centreon::vmware::common::generic_performance_values_historic(
|
||||
$self->{connector},
|
||||
$result2,
|
||||
[
|
||||
{ label => 'disk.numberRead.summation', instances => ['*'] },
|
||||
{ label => 'disk.numberWrite.summation', instances => ['*'] }
|
||||
],
|
||||
$self->{connector}->{perfcounter_speriod},
|
||||
sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift},
|
||||
skip_undef_counter => 1, multiples => 1
|
||||
);
|
||||
|
||||
return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1);
|
||||
|
||||
foreach (keys %$values) {
|
||||
my ($vm_id, $id, $disk_name) = split(/:/);
|
||||
|
||||
# RDM Disk. We skip. Don't know how to manage it right now.
|
||||
next if (!defined($disk_name{$disk_name}));
|
||||
|
||||
my $tmp_value = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$_} / $interval_sec));
|
||||
$datastore_lun{$disk_name{$disk_name}}{$self->{connector}->{perfcounter_cache_reverse}->{$id}} += $tmp_value;
|
||||
if (!defined($datastore_lun{$disk_name{$disk_name}}{$vm_id . '_' . $self->{connector}->{perfcounter_cache_reverse}->{$id}})) {
|
||||
$datastore_lun{$disk_name{$disk_name}}{$vm_id . '_' . $self->{connector}->{perfcounter_cache_reverse}->{$id}} = $tmp_value;
|
||||
} else {
|
||||
$datastore_lun{$disk_name{$disk_name}}{$vm_id . '_' . $self->{connector}->{perfcounter_cache_reverse}->{$id}} += $tmp_value;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (keys %datastore_lun) {
|
||||
my $total_read_counter = $datastore_lun{$_}{'disk.numberRead.summation'};
|
||||
my $total_write_counter = $datastore_lun{$_}{'disk.numberWrite.summation'};
|
||||
|
||||
$data->{$_}->{'disk.numberRead.summation'} = $total_read_counter;
|
||||
$data->{$_}->{'disk.numberWrite.summation'} = $total_write_counter;
|
||||
$data->{$_}->{vm} = {};
|
||||
|
||||
$self->vm_iops_details(
|
||||
label => 'disk.numberRead.summation',
|
||||
type => 'read',
|
||||
detail => $datastore_lun{$_},
|
||||
ref_vm => $moref_vm,
|
||||
data_vm => $data->{$_}->{vm}
|
||||
);
|
||||
$self->vm_iops_details(
|
||||
label => 'disk.numberWrite.summation',
|
||||
type => 'write',
|
||||
detail => $datastore_lun{$_},
|
||||
ref_vm => $moref_vm,
|
||||
data_vm => $data->{$_}->{vm}
|
||||
);
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
sub vm_iops_details {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach my $value (keys %{$options{detail}}) {
|
||||
# display only for high iops
|
||||
if ($value =~ /^vm.*?$options{label}$/ && $options{detail}->{$value} >= $self->{detail_iops_min}) {
|
||||
my ($vm_id) = split(/_/, $value);
|
||||
$options{data_vm}->{$options{ref_vm}->{$vm_id}} = {} if (!defined($options{data_vm}->{$options{ref_vm}->{$vm_id}}));
|
||||
$options{data_vm}->{$options{ref_vm}->{$vm_id}}->{$options{label}} = $options{detail}->{$value};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,114 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmddatastoresnapshot;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'datastoresnapshot';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{datastore_name}) && $options{arguments}->{datastore_name} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: datastore name cannot be null");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'datastore_name', is_regexp => 'filter');
|
||||
my @properties = ('summary.accessible', 'summary.name', 'browser');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'Datastore', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my @ds_array = ();
|
||||
my %ds_names = ();
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
$data->{$entity_value} = {
|
||||
name => $entity_view->{'summary.name'},
|
||||
accessible => $entity_view->{'summary.accessible'},
|
||||
error_message => '',
|
||||
snapshost => [],
|
||||
};
|
||||
next if (centreon::vmware::common::is_accessible(accessible => $entity_view->{'summary.accessible'}) == 0);
|
||||
if (defined($entity_view->browser)) {
|
||||
push @ds_array, $entity_view->browser;
|
||||
$ds_names{$entity_view->{mo_ref}->{value}} = $entity_view->{'summary.name'};
|
||||
}
|
||||
}
|
||||
|
||||
@properties = ();
|
||||
my $result2;
|
||||
return if (!($result2 = centreon::vmware::common::get_views($self->{connector}, \@ds_array, \@properties)));
|
||||
|
||||
foreach my $browse_ds (@$result2) {
|
||||
my $dsName;
|
||||
my $tmp_name = $browse_ds->{mo_ref}->{value};
|
||||
$tmp_name =~ s/^datastoreBrowser-//i;
|
||||
$dsName = $ds_names{$tmp_name};
|
||||
|
||||
my ($snapshots, $msg) = centreon::vmware::common::search_in_datastore(
|
||||
connector => $self->{connector},
|
||||
browse_ds => $browse_ds,
|
||||
ds_name => '[' . $dsName . ']',
|
||||
matchPattern => [ "*.vmsn", "*.vmsd", "*-000*.vmdk", "*-000*delta.vmdk" ],
|
||||
searchCaseInsensitive => 1,
|
||||
query => [ FileQuery->new()],
|
||||
return => 1
|
||||
);
|
||||
if (!defined($snapshots)) {
|
||||
$msg =~ s/\n/ /g;
|
||||
if ($msg =~ /NoPermissionFault/i) {
|
||||
$msg = "Not enough permissions";
|
||||
}
|
||||
|
||||
$data->{$tmp_name}->{error_message} = $msg;
|
||||
next;
|
||||
}
|
||||
|
||||
foreach (@$snapshots) {
|
||||
if (defined($_->file)) {
|
||||
foreach my $x (@{$_->file}) {
|
||||
push @{$data->{$tmp_name}->{snapshost}}, { folder_path => $_->folderPath, path => $x->path, size => $x->fileSize };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,115 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmddatastoreusage;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'datastoreusage';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{datastore_name}) && $options{arguments}->{datastore_name} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: datastore name cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $multiple = 0;
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'datastore_name', is_regexp => 'filter');
|
||||
my @properties = ('summary', 'host');
|
||||
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'Datastore', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $mapped_host = {};
|
||||
my $host_array = [];
|
||||
foreach my $entity_view (@$result) {
|
||||
if (defined($entity_view->host)) {
|
||||
foreach (@{$entity_view->host}) {
|
||||
if (!defined($mapped_host->{ $_->{key}->{value} } )) {
|
||||
push @$host_array, $_->{key};
|
||||
$mapped_host->{ $_->{key}->{value} } = '-';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (scalar(@$host_array) > 0) {
|
||||
my $result_hosts = centreon::vmware::common::get_views($self->{connector}, $host_array, ['name']);
|
||||
foreach (@$result_hosts) {
|
||||
$mapped_host->{ $_->{mo_ref}->{value} } = $_->{name};
|
||||
}
|
||||
}
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
|
||||
$data->{$entity_value} = { name => $entity_view->summary->name, accessible => $entity_view->summary->accessible, hosts => [] };
|
||||
if (defined($entity_view->host)) {
|
||||
foreach (@{$entity_view->host}) {
|
||||
push @{$data->{$entity_value}->{hosts}}, $mapped_host->{ $_->{key}->{value} };
|
||||
}
|
||||
}
|
||||
|
||||
next if (centreon::vmware::common::is_accessible(accessible => $entity_view->summary->accessible) == 0);
|
||||
|
||||
if (defined($self->{refresh})) {
|
||||
$entity_view->RefreshDatastore();
|
||||
}
|
||||
|
||||
# capacity 0...
|
||||
if ($entity_view->summary->capacity <= 0) {
|
||||
$data->{$entity_value}->{size} = 0;
|
||||
next;
|
||||
}
|
||||
|
||||
# in Bytes
|
||||
$data->{$entity_value}->{size} = $entity_view->summary->capacity;
|
||||
$data->{$entity_value}->{free} = $entity_view->summary->freeSpace;
|
||||
|
||||
my ($total_uncommited, $prct_uncommited);
|
||||
my $msg_uncommited = '';
|
||||
if (defined($entity_view->summary->uncommitted)) {
|
||||
$data->{$entity_value}->{uncommitted} = $entity_view->summary->uncommitted;
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,188 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmddatastorevm;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
use File::Basename;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'datastorevm';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: vm hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
if (defined($options{arguments}->{datastore_name}) && $options{arguments}->{datastore_name} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: datastore name cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{connector}->{perfcounter_speriod} > 0)) {
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
my $multiple = 0;
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'vm_hostname', is_regexp => 'filter');
|
||||
$self->add_filter(filters => $filters, label => 'config.annotation', search_option => 'filter_description');
|
||||
$self->add_filter(filters => $filters, label => 'config.guestFullName', search_option => 'filter_os');
|
||||
$self->add_filter(filters => $filters, label => 'config.uuid', search_option => 'filter_uuid');
|
||||
|
||||
my @properties = ('name', 'datastore', 'runtime.connectionState', 'runtime.powerState');
|
||||
if (defined($self->{display_description})) {
|
||||
push @properties, 'config.annotation';
|
||||
}
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'VirtualMachine', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $ds_regexp;
|
||||
if (defined($self->{datastore_name}) && !defined($self->{filter_datastore})) {
|
||||
$ds_regexp = qr/^\Q$self->{datastore_name}\E$/;
|
||||
} elsif (!defined($self->{datastore_name})) {
|
||||
$ds_regexp = qr/.*/;
|
||||
} else {
|
||||
$ds_regexp = qr/$self->{datastore_name}/;
|
||||
}
|
||||
|
||||
my $data = {};
|
||||
my $mapped_datastore = {};
|
||||
my @ds_array = ();
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
|
||||
$data->{$entity_value} = {
|
||||
name => $entity_view->{name},
|
||||
connection_state => $entity_view->{'runtime.connectionState'}->val,
|
||||
power_state => $entity_view->{'runtime.powerState'}->val,
|
||||
'config.annotation' => defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : undef,
|
||||
datastore => {},
|
||||
};
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
next if (centreon::vmware::common::is_running(power => $entity_view->{'runtime.powerState'}->val) == 0);
|
||||
|
||||
if (defined($entity_view->datastore)) {
|
||||
foreach (@{$entity_view->datastore}) {
|
||||
if (!defined($mapped_datastore->{$_->value})) {
|
||||
push @ds_array, $_;
|
||||
$mapped_datastore->{$_->value} = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (scalar(@ds_array) == 0) {
|
||||
centreon::vmware::common::set_response(code => 200, short_message => "no virtual machines running or no datastore found");
|
||||
return ;
|
||||
}
|
||||
|
||||
@properties = ('info');
|
||||
my $result2 = centreon::vmware::common::get_views($self->{connector}, \@ds_array, \@properties);
|
||||
return if (!defined($result2));
|
||||
|
||||
#my %uuid_list = ();
|
||||
my %disk_name = ();
|
||||
my %datastore_lun = ();
|
||||
foreach (@$result2) {
|
||||
if ($_->info->isa('VmfsDatastoreInfo')) {
|
||||
#$uuid_list{$_->volume->uuid} = $_->volume->name;
|
||||
# Not need. We are on Datastore level (not LUN level)
|
||||
foreach my $extent (@{$_->info->vmfs->extent}) {
|
||||
$disk_name{$extent->diskName} = $_->info->vmfs->name;
|
||||
}
|
||||
}
|
||||
#if ($_->info->isa('NasDatastoreInfo')) {
|
||||
# Zero disk Info
|
||||
#}
|
||||
}
|
||||
|
||||
# Vsphere >= 4.1
|
||||
# We don't filter. To filter we'll need to get disk from vms
|
||||
my $values = centreon::vmware::common::generic_performance_values_historic($self->{connector},
|
||||
$result,
|
||||
[{label => 'disk.numberRead.summation', instances => ['*']},
|
||||
{label => 'disk.numberWrite.summation', instances => ['*']},
|
||||
{label => 'disk.maxTotalLatency.latest', instances => ['']}],
|
||||
$self->{connector}->{perfcounter_speriod},
|
||||
sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift},
|
||||
skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1);
|
||||
return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1);
|
||||
|
||||
my $interval_sec = $self->{connector}->{perfcounter_speriod};
|
||||
if (defined($self->{sampling_period}) && $self->{sampling_period} ne '') {
|
||||
$interval_sec = $self->{sampling_period};
|
||||
}
|
||||
|
||||
my $finded = 0;
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0 &&
|
||||
centreon::vmware::common::is_running(power => $entity_view->{'runtime.powerState'}->val) == 0);
|
||||
|
||||
my %datastore_lun = ();
|
||||
foreach (keys %{$values->{$entity_value}}) {
|
||||
my ($id, $disk_name) = split /:/;
|
||||
|
||||
# RDM Disk. We skip. Don't know how to manage it right now.
|
||||
next if (!defined($disk_name{$disk_name}));
|
||||
# We skip datastore not filtered
|
||||
next if ($disk_name{$disk_name} !~ /$ds_regexp/);
|
||||
$datastore_lun{$disk_name{$disk_name}} = { 'disk.numberRead.summation' => 0,
|
||||
'disk.numberWrite.summation' => 0 } if (!defined($datastore_lun{$disk_name{$disk_name}}));
|
||||
$datastore_lun{$disk_name{$disk_name}}->{$self->{connector}->{perfcounter_cache_reverse}->{$id}} += $values->{$entity_value}->{$_};
|
||||
}
|
||||
|
||||
foreach (sort keys %datastore_lun) {
|
||||
my $read_counter = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($datastore_lun{$_}{'disk.numberRead.summation'} / $interval_sec));
|
||||
my $write_counter = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($datastore_lun{$_}{'disk.numberWrite.summation'} / $interval_sec));
|
||||
|
||||
$data->{$entity_value}->{datastore}->{$_} = {
|
||||
'disk.numberRead.summation' => $read_counter,
|
||||
'disk.numberWrite.summation' => $write_counter,
|
||||
};
|
||||
}
|
||||
|
||||
my $max_total_latency = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'disk.maxTotalLatency.latest'}->{key} . ":"}));
|
||||
$data->{$entity_value}->{'disk.maxTotalLatency.latest'} = $max_total_latency;
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,96 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmddevicevm;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'devicevm';
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: vm hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{connector}->{perfcounter_speriod} > 0)) {
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'vm_hostname', is_regexp => 'filter');
|
||||
$self->add_filter(filters => $filters, label => 'config.annotation', search_option => 'filter_description');
|
||||
$self->add_filter(filters => $filters, label => 'config.guestFullName', search_option => 'filter_os');
|
||||
$self->add_filter(filters => $filters, label => 'config.uuid', search_option => 'filter_uuid');
|
||||
|
||||
my @properties = ('name', 'runtime.connectionState', 'runtime.powerState', 'config.hardware.device');
|
||||
if (defined($self->{display_description})) {
|
||||
push @properties, 'config.annotation';
|
||||
}
|
||||
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'VirtualMachine', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $data = {};
|
||||
my $total_device_connected = 0;
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
|
||||
$data->{$entity_value} = {
|
||||
name => $entity_view->{name},
|
||||
connection_state => $entity_view->{'runtime.connectionState'}->val,
|
||||
power_state => $entity_view->{'runtime.powerState'}->val,
|
||||
'config.annotation' => defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : undef,
|
||||
total_device_connected => 0,
|
||||
};
|
||||
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
next if (centreon::vmware::common::is_running(power => $entity_view->{'runtime.powerState'}->val) == 0);
|
||||
|
||||
foreach my $dev (@{$entity_view->{'config.hardware.device'}}) {
|
||||
if (ref($dev) =~ /$self->{device}/) {
|
||||
if (defined($dev->connectable) && $dev->connectable->connected == 1) {
|
||||
$data->{$entity_value}->{total_device_connected}++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,248 @@
|
|||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package centreon::vmware::cmddiscovery;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
use centreon::vmware::cisTags;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'discovery';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{resource_type}) && $options{arguments}->{resource_type} !~ /^vm$|^esx$/) {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: resource type must be 'vm' or 'esx'");
|
||||
return 1;
|
||||
}
|
||||
|
||||
$self->{tags} = $options{arguments}->{tags} if (defined($options{arguments}->{tags}));
|
||||
$self->{resource_type} = $options{arguments}->{resource_type} if (defined($options{arguments}->{resource_type}));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub get_folders {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $folder = $options{folder};
|
||||
my $parent = $options{parent};
|
||||
my $value = $options{value};
|
||||
|
||||
$parent .= '/' . $folder->name;
|
||||
$self->{paths}->{$value} = $parent;
|
||||
|
||||
my $children = $folder->childEntity || return;
|
||||
for my $child (@{$children}) {
|
||||
next if ($child->type ne 'Folder');
|
||||
|
||||
$self->get_folders(
|
||||
folder => centreon::vmware::common::get_view($self->{connector}, $child),
|
||||
parent => $parent,
|
||||
value => $child->value
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my @disco_data;
|
||||
my $disco_stats;
|
||||
|
||||
my ($rv, $tags);
|
||||
my $customFields = {};
|
||||
|
||||
my $api_type = $self->{connector}->{session}->get_service_content()->about->apiType;
|
||||
if ($api_type eq 'VirtualCenter') {
|
||||
my $entries = centreon::vmware::common::get_view($self->{connector}, $self->{connector}->{session}->get_service_content()->customFieldsManager);
|
||||
if (defined($entries->{field})) {
|
||||
foreach (@{$entries->{field}}) {
|
||||
$customFields->{ $_->{key} } = $_->{name};
|
||||
}
|
||||
}
|
||||
|
||||
if (defined($self->{tags})) {
|
||||
my $cisTags = centreon::vmware::cisTags->new();
|
||||
$cisTags->configuration(
|
||||
url => $self->{connector}->{config_vsphere_url},
|
||||
username => $self->{connector}->{config_vsphere_user},
|
||||
password => $self->{connector}->{config_vsphere_pass},
|
||||
logger => $self->{connector}->{logger}
|
||||
);
|
||||
($rv, $tags) = $cisTags->tagsByResource();
|
||||
if ($rv) {
|
||||
$self->{connector}->{logger}->writeLogError("cannot get tags: " . $cisTags->error());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$disco_stats->{start_time} = time();
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'datacenter', is_regexp => 'filter');
|
||||
my @properties = ('name', 'hostFolder', 'vmFolder');
|
||||
|
||||
my $datacenters = centreon::vmware::common::search_entities(
|
||||
command => $self,
|
||||
view_type => 'Datacenter',
|
||||
properties => \@properties,
|
||||
filter => $filters
|
||||
);
|
||||
return if (!defined($datacenters));
|
||||
|
||||
foreach my $datacenter (@{$datacenters}) {
|
||||
my @properties = ('name', 'host');
|
||||
|
||||
$self->get_folders(
|
||||
folder => centreon::vmware::common::get_view($self->{connector}, $datacenter->vmFolder),
|
||||
parent => '',
|
||||
value => $datacenter->vmFolder->value
|
||||
);
|
||||
|
||||
my ($status, $clusters) = centreon::vmware::common::find_entity_views(
|
||||
connector => $self->{connector},
|
||||
view_type => 'ComputeResource', # ClusterComputeResource extends ComputeResource. so no need to check it
|
||||
properties => \@properties,
|
||||
filter => $filters,
|
||||
begin_entity => $datacenter,
|
||||
output_message => 0
|
||||
);
|
||||
next if ($status <= 0);
|
||||
|
||||
foreach my $cluster (@$clusters) {
|
||||
next if (!$cluster->{'host'});
|
||||
|
||||
my @properties = (
|
||||
'name', 'vm', 'config.virtualNicManagerInfo.netConfig', 'config.product.version',
|
||||
'config.product.productLineId', 'hardware.systemInfo.vendor', 'hardware.systemInfo.model',
|
||||
'hardware.systemInfo.uuid', 'runtime.powerState', 'runtime.inMaintenanceMode', 'runtime.connectionState'
|
||||
);
|
||||
if ($api_type eq 'VirtualCenter') {
|
||||
push @properties, 'summary.customValue';
|
||||
}
|
||||
|
||||
my $esxs = centreon::vmware::common::get_views($self->{connector}, \@{$cluster->host}, \@properties);
|
||||
next if (!defined($esxs));
|
||||
|
||||
foreach my $esx (@$esxs) {
|
||||
my %esx;
|
||||
|
||||
my $customValuesEsx = [];
|
||||
if (defined($esx->{'summary.customValue'})) {
|
||||
foreach (@{$esx->{'summary.customValue'}}) {
|
||||
push @$customValuesEsx, { key => $customFields->{ $_->{key} }, value => $_->{value} };
|
||||
}
|
||||
}
|
||||
$esx{type} = 'esx';
|
||||
$esx{name} = $esx->name;
|
||||
$esx{os} = $esx->{'config.product.productLineId'} . ' ' . $esx->{'config.product.version'};
|
||||
$esx{hardware} = $esx->{'hardware.systemInfo.vendor'} . ' ' . $esx->{'hardware.systemInfo.model'};
|
||||
$esx{power_state} = $esx->{'runtime.powerState'}->val;
|
||||
$esx{connection_state} = $esx->{'runtime.connectionState'}->val;
|
||||
$esx{maintenance} = $esx->{'runtime.inMaintenanceMode'};
|
||||
$esx{datacenter} = $datacenter->name;
|
||||
$esx{cluster} = $cluster->name;
|
||||
$esx{custom_attributes} = $customValuesEsx;
|
||||
$esx{tags} = [];
|
||||
if (defined($tags)) {
|
||||
$esx{tags} = $tags->{esx}->{ $esx->{mo_ref}->{value} } if (defined($tags->{esx}->{ $esx->{mo_ref}->{value} }));
|
||||
}
|
||||
|
||||
foreach my $nic (@{$esx->{'config.virtualNicManagerInfo.netConfig'}}) {
|
||||
my %lookup = map { $_->{'key'} => $_->{'spec'}->{'ip'}->{'ipAddress'} } @{$nic->{'candidateVnic'}};
|
||||
foreach my $vnic (@{$nic->{'selectedVnic'}}) {
|
||||
push @{$esx{'ip_' . $nic->{'nicType'}}}, $lookup{$vnic};
|
||||
}
|
||||
}
|
||||
|
||||
push @disco_data, \%esx if (defined($self->{resource_type}) && $self->{resource_type} eq 'esx');
|
||||
next if (!defined($self->{resource_type}) || $self->{resource_type} ne 'vm');
|
||||
next if (!$esx->vm);
|
||||
|
||||
@properties = (
|
||||
'parent', 'config.name', 'config.annotation', 'config.template', 'config.uuid', 'config.version',
|
||||
'config.guestId', 'guest.guestState', 'guest.hostName', 'guest.ipAddress', 'runtime.powerState'
|
||||
);
|
||||
if ($api_type eq 'VirtualCenter') {
|
||||
push @properties, 'summary.customValue';
|
||||
}
|
||||
|
||||
my $vms = centreon::vmware::common::get_views($self->{connector}, \@{$esx->vm}, \@properties);
|
||||
next if (!defined($vms));
|
||||
|
||||
foreach my $vm (@{$vms}) {
|
||||
next if ($vm->{'config.template'} eq 'true');
|
||||
next if (!defined($vm->{'config.uuid'}) || $vm->{'config.uuid'} eq '');
|
||||
my $entry;
|
||||
|
||||
my $customValuesVm = [];
|
||||
if (defined($vm->{'summary.customValue'})) {
|
||||
foreach (@{$vm->{'summary.customValue'}}) {
|
||||
push @$customValuesVm, { key => $customFields->{ $_->{key} }, value => $_->{value} };
|
||||
}
|
||||
}
|
||||
$entry->{type} = 'vm';
|
||||
$entry->{name} = $vm->{'config.name'};
|
||||
$entry->{uuid} = $vm->{'config.uuid'};
|
||||
$entry->{folder} = (defined($vm->parent) && $vm->parent->type eq 'Folder') ? $self->{paths}->{$vm->parent->value} : '';
|
||||
$entry->{annotation} = $vm->{'config.annotation'};
|
||||
$entry->{annotation} =~ s/\n/ /g if (defined($entry->{annotation}));
|
||||
$entry->{os} = $vm->{'config.guestId'};
|
||||
$entry->{hardware} = $vm->{'config.version'};
|
||||
$entry->{guest_name} = $vm->{'guest.hostName'};
|
||||
$entry->{guest_ip} = $vm->{'guest.ipAddress'};
|
||||
$entry->{guest_state} = $vm->{'guest.guestState'};
|
||||
$entry->{power_state} = $vm->{'runtime.powerState'}->val;
|
||||
$entry->{datacenter} = $datacenter->name;
|
||||
$entry->{cluster} = $cluster->name;
|
||||
$entry->{custom_attributes} = $customValuesVm;
|
||||
$entry->{esx} = $esx->name;
|
||||
$entry->{tags} = [];
|
||||
if (defined($tags)) {
|
||||
$entry->{tags} = $tags->{vm}->{ $vm->{mo_ref}->{value} } if (defined($tags->{vm}->{ $vm->{mo_ref}->{value} }));
|
||||
}
|
||||
|
||||
push @disco_data, $entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$disco_stats->{end_time} = time();
|
||||
$disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time};
|
||||
$disco_stats->{discovered_items} = @disco_data;
|
||||
$disco_stats->{results} = \@disco_data;
|
||||
|
||||
centreon::vmware::common::set_response(data => $disco_stats);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,87 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdgetmap;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'getmap';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter');
|
||||
my @properties = ('name', 'vm', 'config.product.version');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
|
||||
$data->{$entity_value} = {
|
||||
name => $entity_view->{name},
|
||||
version => $entity_view->{'config.product.version'},
|
||||
vm => {}
|
||||
};
|
||||
|
||||
next if (defined($self->{vm_no}));
|
||||
|
||||
my @vm_array = ();
|
||||
if (defined $entity_view->vm) {
|
||||
@vm_array = (@vm_array, @{$entity_view->vm});
|
||||
}
|
||||
|
||||
@properties = ('name', 'summary.runtime.powerState');
|
||||
my $result2 = centreon::vmware::common::get_views($self->{connector}, \@vm_array, \@properties);
|
||||
return if (!defined($result2));
|
||||
|
||||
foreach my $vm (@$result2) {
|
||||
$data->{$entity_value}->{vm}->{$vm->{mo_ref}->{value}} = {
|
||||
name => $vm->name,
|
||||
power_state => $vm->{'summary.runtime.powerState'}->val,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,113 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdhealthhost;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'healthhost';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter');
|
||||
my @properties = (
|
||||
'name', 'runtime.healthSystemRuntime.hardwareStatusInfo', 'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo',
|
||||
'runtime.connectionState'
|
||||
);
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
$data->{$entity_value} = { name => $entity_view->{name}, state => $entity_view->{'runtime.connectionState'}->val };
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
|
||||
my $cpuStatusInfo = $entity_view->{'runtime.healthSystemRuntime.hardwareStatusInfo'}->{cpuStatusInfo};
|
||||
my $memoryStatusInfo = $entity_view->{'runtime.healthSystemRuntime.hardwareStatusInfo'}->{memoryStatusInfo};
|
||||
my $storageStatusInfo = $entity_view->{'runtime.healthSystemRuntime.hardwareStatusInfo'}->{storageStatusInfo};
|
||||
my $numericSensorInfo = $entity_view->{'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo'};
|
||||
|
||||
# CPU
|
||||
if (defined($cpuStatusInfo)) {
|
||||
$data->{$entity_value}->{cpu_info} = [];
|
||||
foreach (@$cpuStatusInfo) {
|
||||
push @{$data->{$entity_value}->{cpu_info}}, { status => $_->status->key, name => $_->name, summary => $_->status->summary };
|
||||
}
|
||||
}
|
||||
|
||||
# Memory
|
||||
if (defined($memoryStatusInfo)) {
|
||||
$data->{$entity_value}->{memory_info} = [];
|
||||
foreach (@$memoryStatusInfo) {
|
||||
push @{$data->{$entity_value}->{memory_info}}, { status => $_->status->key, name => $_->name, summary => $_->status->summary };
|
||||
}
|
||||
}
|
||||
|
||||
# Storage
|
||||
if (defined($self->{storage_status}) && defined($storageStatusInfo)) {
|
||||
$data->{$entity_value}->{storage_info} = [];
|
||||
foreach (@$storageStatusInfo) {
|
||||
push @{$data->{$entity_value}->{storage_info}}, { status => $_->status->key, name => $_->name, summary => $_->status->summary };
|
||||
}
|
||||
}
|
||||
|
||||
# Sensor
|
||||
if (defined($numericSensorInfo)) {
|
||||
$data->{$entity_value}->{sensor_info} = [];
|
||||
foreach (@$numericSensorInfo) {
|
||||
push @{$data->{$entity_value}->{sensor_info}}, {
|
||||
status => $_->healthState->key,
|
||||
type => $_->sensorType, name => $_->name,
|
||||
summary => $_->healthState->summary,
|
||||
current_reading => $_->currentReading,
|
||||
power10 => $_->unitModifier,
|
||||
unit => $_->baseUnits
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,67 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdlicenses;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'licenses';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $entries = centreon::vmware::common::get_view($self->{connector}, $self->{connector}->{session}->get_service_content()->licenseManager);
|
||||
|
||||
my $data = {};
|
||||
if (defined($entries->licenses)) {
|
||||
foreach my $license (@{$entries->licenses}) {
|
||||
$data->{ $license->{name} } = {
|
||||
total => $license->{total},
|
||||
used => $license->{used},
|
||||
edition => $license->{editionKey}
|
||||
};
|
||||
foreach my $prop (@{$license->{properties}}) {
|
||||
if ($prop->{key} eq 'expirationMinutes') {
|
||||
$data->{ $license->{name} }->{expiration_minutes} = $prop->{value};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,108 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdlimitvm;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'limitvm';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: vm hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'vm_hostname', is_regexp => 'filter');
|
||||
$self->add_filter(filters => $filters, label => 'config.annotation', search_option => 'filter_description');
|
||||
$self->add_filter(filters => $filters, label => 'config.guestFullName', search_option => 'filter_os');
|
||||
$self->add_filter(filters => $filters, label => 'config.uuid', search_option => 'filter_uuid');
|
||||
|
||||
my @properties = ('name', 'runtime.connectionState', 'runtime.powerState', 'config.cpuAllocation.limit', 'config.memoryAllocation.limit');
|
||||
if (defined($self->{check_disk_limit})) {
|
||||
push @properties, 'config.hardware.device';
|
||||
}
|
||||
if (defined($self->{display_description})) {
|
||||
push @properties, 'config.annotation';
|
||||
}
|
||||
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'VirtualMachine', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
|
||||
$data->{$entity_value} = {
|
||||
name => $entity_view->{name},
|
||||
connection_state => $entity_view->{'runtime.connectionState'}->val,
|
||||
power_state => $entity_view->{'runtime.powerState'}->val,
|
||||
'config.annotation' => defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : undef,
|
||||
'config.cpuAllocation.limit' => -1,
|
||||
'config.memoryAllocation.limit' => -1,
|
||||
'config.storageIOAllocation.limit' => [],
|
||||
};
|
||||
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
|
||||
# CPU Limit
|
||||
if (defined($entity_view->{'config.cpuAllocation.limit'}) && $entity_view->{'config.cpuAllocation.limit'} != -1) {
|
||||
$data->{$entity_value}->{'config.cpuAllocation.limit'} = $entity_view->{'config.cpuAllocation.limit'};
|
||||
}
|
||||
|
||||
# Memory Limit
|
||||
if (defined($entity_view->{'config.memoryAllocation.limit'}) && $entity_view->{'config.memoryAllocation.limit'} != -1) {
|
||||
$data->{$entity_value}->{'config.memoryAllocation.limit'} = $entity_view->{'config.memoryAllocation.limit'};
|
||||
}
|
||||
|
||||
# Disk
|
||||
if (defined($self->{check_disk_limit})) {
|
||||
foreach my $device (@{$entity_view->{'config.hardware.device'}}) {
|
||||
if ($device->isa('VirtualDisk')) {
|
||||
if (defined($device->storageIOAllocation->limit) && $device->storageIOAllocation->limit != -1) {
|
||||
push @{$data->{$entity_value}->{'config.storageIOAllocation.limit'}}, { name => $device->backing->fileName, limit => $device->storageIOAllocation->limit };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,64 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdlistclusters;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'listclusters';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{cluster}) && $options{arguments}->{cluster} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: cluster cannot be null");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'cluster', is_regexp => 'filter');
|
||||
my @properties = ('name');
|
||||
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'ClusterComputeResource', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $data = {};
|
||||
foreach my $cluster (@$result) {
|
||||
$data->{$cluster->{mo_ref}->{value}} = { name => $cluster->name };
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,64 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdlistdatacenters;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'listdatacenters';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{datacenter}) && $options{arguments}->{datacenter} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: datacenter cannot be null");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'datacenter', is_regexp => 'filter');
|
||||
my @properties = ('name');
|
||||
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'Datacenter', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $data = {};
|
||||
foreach my $datacenter (@$result) {
|
||||
$data->{$datacenter->{mo_ref}->{value}} = { name => $datacenter->{name} };
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,69 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdlistdatastores;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'listdatastores';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $multiple = 0;
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'datastore_name', is_regexp => 'filter');
|
||||
my @properties = ('summary');
|
||||
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'Datastore', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $data = {};
|
||||
foreach my $datastore (@$result) {
|
||||
$data->{$datastore->{mo_ref}->{value}} = {
|
||||
name => $datastore->summary->name,
|
||||
type => $datastore->summary->type,
|
||||
accessible => $datastore->summary->accessible
|
||||
};
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,98 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdlistnichost;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'listnichost';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (!defined($options{arguments}->{esx_hostname}) || $options{arguments}->{esx_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname need to be set");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
my %nic_in_vswitch = ();
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter');
|
||||
my @properties = ('config.network.pnic', 'config.network.vswitch', 'config.network.proxySwitch');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
# Get Name from vswitch
|
||||
if (defined($$result[0]->{'config.network.vswitch'})) {
|
||||
foreach (@{$$result[0]->{'config.network.vswitch'}}) {
|
||||
next if (!defined($_->{pnic}));
|
||||
foreach my $keynic (@{$_->{pnic}}) {
|
||||
$nic_in_vswitch{$keynic} = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
# Get Name from proxySwitch
|
||||
if (defined($$result[0]->{'config.network.proxySwitch'})) {
|
||||
foreach (@{$$result[0]->{'config.network.proxySwitch'}}) {
|
||||
next if (!defined($_->{pnic}));
|
||||
foreach my $keynic (@{$_->{pnic}}) {
|
||||
$nic_in_vswitch{$keynic} = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my %nics = ();
|
||||
foreach (@{$$result[0]->{'config.network.pnic'}}) {
|
||||
if (defined($nic_in_vswitch{$_->key})) {
|
||||
$nics{$_->device}{vswitch} = 1;
|
||||
}
|
||||
if (defined($_->linkSpeed)) {
|
||||
$nics{$_->device}{up} = 1;
|
||||
} else {
|
||||
$nics{$_->device}{down} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
my $data = {};
|
||||
foreach my $nic_name (sort keys %nics) {
|
||||
my $status = defined($nics{$nic_name}{up}) ? 'up' : 'down';
|
||||
my $vswitch = defined($nics{$nic_name}{vswitch}) ? 1 : 0;
|
||||
|
||||
$data->{$nic_name} = { name => $nic_name, status => $status, vswitch => $vswitch };
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,69 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdmaintenancehost;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'maintenancehost';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter');
|
||||
|
||||
my @properties = ('name', 'runtime.inMaintenanceMode', 'runtime.connectionState');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
$data->{$entity_value} = { name => $entity_view->{name}, state => $entity_view->{'runtime.connectionState'}->val };
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
|
||||
$data->{$entity_value}->{inMaintenanceMode} = $entity_view->{'runtime.inMaintenanceMode'};
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,107 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdmemhost;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'memhost';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{connector}->{perfcounter_speriod} > 0)) {
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter');
|
||||
my @properties = ('name', 'summary.hardware.memorySize', 'runtime.connectionState');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $performances = [{'label' => 'mem.consumed.average', 'instances' => ['']},
|
||||
{'label' => 'mem.overhead.average', 'instances' => ['']}];
|
||||
if (!defined($self->{no_memory_state})) {
|
||||
push @{$performances}, {'label' => 'mem.state.latest', 'instances' => ['']};
|
||||
}
|
||||
my $values = centreon::vmware::common::generic_performance_values_historic($self->{connector},
|
||||
$result, $performances,
|
||||
$self->{connector}->{perfcounter_speriod},
|
||||
sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift},
|
||||
skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1);
|
||||
return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1);
|
||||
|
||||
# for mem.state:
|
||||
# 0 (high) Free memory >= 6% of machine memory minus Service Console memory.
|
||||
# 1 (soft) 4%
|
||||
# 2 (hard) 2%
|
||||
# 3 (low) 1%
|
||||
my %mapping_state = (0 => 'high', 1 => 'soft', 2 => 'hard', 3 => 'low');
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
|
||||
$data->{$entity_value} = { name => $entity_view->{name}, state => $entity_view->{'runtime.connectionState'}->val };
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
|
||||
my $memory_size = $entity_view->{'summary.hardware.memorySize'}; # in B
|
||||
|
||||
# in KB
|
||||
my $mem_used = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.consumed.average'}->{'key'} . ":"})) * 1024;
|
||||
my $mem_overhead = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.overhead.average'}->{'key'} . ":"})) * 1024;
|
||||
my $mem_state;
|
||||
if (!defined($self->{no_memory_state})) {
|
||||
$mem_state = centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.state.latest'}->{'key'} . ":"});
|
||||
}
|
||||
|
||||
$data->{$entity_value}->{mem_size} = $memory_size;
|
||||
$data->{$entity_value}->{'mem.consumed.average'} = $mem_used;
|
||||
$data->{$entity_value}->{'mem.overhead.average'} = $mem_overhead;
|
||||
$data->{$entity_value}->{mem_state_str} = defined($mem_state) ? $mapping_state{$mem_state} : undef;
|
||||
$data->{$entity_value}->{mem_state} = defined($mem_state) ? $mem_state : undef;
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,112 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdmemvm;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'memvm';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: vm hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{connector}->{perfcounter_speriod} > 0)) {
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'vm_hostname', is_regexp => 'filter');
|
||||
$self->add_filter(filters => $filters, label => 'config.annotation', search_option => 'filter_description');
|
||||
$self->add_filter(filters => $filters, label => 'config.guestFullName', search_option => 'filter_os');
|
||||
$self->add_filter(filters => $filters, label => 'config.uuid', search_option => 'filter_uuid');
|
||||
|
||||
my @properties = ('name', 'summary.config.memorySizeMB', 'runtime.connectionState', 'runtime.powerState');
|
||||
if (defined($self->{display_description})) {
|
||||
push @properties, 'config.annotation';
|
||||
}
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'VirtualMachine', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $values = centreon::vmware::common::generic_performance_values_historic($self->{connector},
|
||||
$result,
|
||||
[{label => 'mem.active.average', instances => ['']},
|
||||
{label => 'mem.overhead.average', instances => ['']},
|
||||
{label => 'mem.vmmemctl.average', instances => ['']},
|
||||
{label => 'mem.consumed.average', instances => ['']},
|
||||
{label => 'mem.shared.average', instances => ['']}],
|
||||
$self->{connector}->{perfcounter_speriod},
|
||||
sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift},
|
||||
skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1);
|
||||
return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1);
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
|
||||
$data->{$entity_value} = {
|
||||
name => $entity_view->{name},
|
||||
connection_state => $entity_view->{'runtime.connectionState'}->val,
|
||||
power_state => $entity_view->{'runtime.powerState'}->val,
|
||||
'config.annotation' => defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : undef,
|
||||
};
|
||||
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
next if (centreon::vmware::common::is_running(power => $entity_view->{'runtime.powerState'}->val) == 0);
|
||||
|
||||
# in KB
|
||||
my $mem_consumed = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.consumed.average'}->{'key'} . ":"})) * 1024;
|
||||
my $mem_active = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.active.average'}->{'key'} . ":"})) * 1024;
|
||||
my $mem_overhead = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.overhead.average'}->{'key'} . ":"})) * 1024;
|
||||
my $mem_ballooning = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.vmmemctl.average'}->{'key'} . ":"})) * 1024;
|
||||
my $mem_shared = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.shared.average'}->{'key'} . ":"})) * 1024;
|
||||
|
||||
$data->{$entity_value}->{'memory_size'} = $entity_view->{'summary.config.memorySizeMB'} * 1024 * 1024;
|
||||
$data->{$entity_value}->{'mem.consumed.average'} = $mem_consumed;
|
||||
$data->{$entity_value}->{'mem.active.average'} = $mem_active;
|
||||
$data->{$entity_value}->{'mem.overhead.average'} = $mem_overhead;
|
||||
$data->{$entity_value}->{'mem.vmmemctl.average'} = $mem_ballooning;
|
||||
$data->{$entity_value}->{'mem.shared.average'} = $mem_shared;
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,158 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdnethost;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'nethost';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq '') {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => 'Argument error: esx hostname cannot be null');
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{connector}->{perfcounter_speriod} > 0)) {
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
my $number_nic = 0;
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter');
|
||||
my @properties = ('name', 'config.network.pnic', 'runtime.connectionState', 'config.network.vswitch');
|
||||
if (!defined($self->{no_proxyswitch})) {
|
||||
push @properties, 'config.network.proxySwitch';
|
||||
}
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $data = {};
|
||||
my $pnic_def_up = {};
|
||||
my $query_perfs = [];
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
$data->{$entity_value} = { name => $entity_view->{name}, state => $entity_view->{'runtime.connectionState'}->val,
|
||||
pnic => { }, vswitch => { }, proxyswitch => {} };
|
||||
next if ($entity_view->{'runtime.connectionState'}->val !~ /^connected$/i);
|
||||
|
||||
$pnic_def_up->{$entity_value} = {};
|
||||
my $instances = [];
|
||||
|
||||
# Get Name from vswitch
|
||||
if (defined($entity_view->{'config.network.vswitch'})) {
|
||||
foreach (@{$entity_view->{'config.network.vswitch'}}) {
|
||||
$data->{$entity_value}->{vswitch}->{$_->{name}} = { pnic => [] };
|
||||
next if (!defined($_->{pnic}));
|
||||
push @{$data->{$entity_value}->{vswitch}->{$_->{name}}->{pnic}}, @{$_->{pnic}};
|
||||
}
|
||||
}
|
||||
# Get Name from proxySwitch
|
||||
if (defined($entity_view->{'config.network.proxySwitch'})) {
|
||||
foreach (@{$entity_view->{'config.network.proxySwitch'}}) {
|
||||
my $name = defined($_->{name}) ? $_->{name} : $_->{key};
|
||||
$data->{$entity_value}->{proxyswitch}->{$name} = { pnic => [] };
|
||||
next if (!defined($_->{pnic}));
|
||||
push @{$data->{$entity_value}->{proxyswitch}->{$name}->{pnic}}, @{$_->{pnic}};
|
||||
}
|
||||
}
|
||||
|
||||
foreach (@{$entity_view->{'config.network.pnic'}}) {
|
||||
$data->{$entity_value}->{pnic}->{$_->device} = { speed => undef, status => 'down', key => $_->{key} };
|
||||
|
||||
$number_nic++;
|
||||
if (defined($_->linkSpeed)) {
|
||||
$data->{$entity_value}->{pnic}->{$_->device}->{speed} = $_->linkSpeed->speedMb;
|
||||
$data->{$entity_value}->{pnic}->{$_->device}->{status} = 'up';
|
||||
|
||||
$pnic_def_up->{$entity_value}->{$_->device} = $_->linkSpeed->speedMb;
|
||||
push @$instances, $_->device;
|
||||
}
|
||||
}
|
||||
|
||||
push @$query_perfs, {
|
||||
entity => $entity_view,
|
||||
metrics => [
|
||||
{label => 'net.received.average', instances => $instances},
|
||||
{label => 'net.transmitted.average', instances => $instances},
|
||||
{label => 'net.droppedRx.summation', instances => $instances},
|
||||
{label => 'net.droppedTx.summation', instances => $instances},
|
||||
{label => 'net.packetsRx.summation', instances => $instances},
|
||||
{label => 'net.packetsTx.summation', instances => $instances}
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
# Nothing to retrieve. problem before already.
|
||||
return if (scalar(@$query_perfs) == 0);
|
||||
|
||||
my $values = centreon::vmware::common::generic_performance_values_historic(
|
||||
$self->{connector},
|
||||
undef,
|
||||
$query_perfs,
|
||||
$self->{connector}->{perfcounter_speriod},
|
||||
sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift},
|
||||
skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1
|
||||
);
|
||||
return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1);
|
||||
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
|
||||
foreach (sort keys %{$pnic_def_up->{$entity_value}}) {
|
||||
# KBps
|
||||
my $traffic_in = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'net.received.average'}->{key} . ":" . $_})) * 1024 * 8;
|
||||
my $traffic_out = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'net.transmitted.average'}->{key} . ":" . $_})) * 1024 * 8;
|
||||
my $packets_in = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'net.packetsRx.summation'}->{key} . ":" . $_}));
|
||||
my $packets_out = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'net.packetsTx.summation'}->{key} . ":" . $_}));
|
||||
my $dropped_in = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'net.droppedRx.summation'}->{key} . ":" . $_}));
|
||||
my $dropped_out = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'net.droppedTx.summation'}->{key} . ":" . $_}));
|
||||
|
||||
$data->{$entity_value}->{pnic}->{$_}->{'net.received.average'} = $traffic_in;
|
||||
$data->{$entity_value}->{pnic}->{$_}->{'net.transmitted.average'} = $traffic_out;
|
||||
$data->{$entity_value}->{pnic}->{$_}->{'net.packetsRx.summation'} = $packets_in;
|
||||
$data->{$entity_value}->{pnic}->{$_}->{'net.packetsTx.summation'} = $packets_out;
|
||||
$data->{$entity_value}->{pnic}->{$_}->{'net.droppedRx.summation'} = $dropped_in;
|
||||
$data->{$entity_value}->{pnic}->{$_}->{'net.droppedTx.summation'} = $dropped_out;
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,113 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdnetvm;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'netvm';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: vm hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{connector}->{perfcounter_speriod} > 0)) {
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'vm_hostname', is_regexp => 'filter');
|
||||
$self->add_filter(filters => $filters, label => 'config.annotation', search_option => 'filter_description');
|
||||
$self->add_filter(filters => $filters, label => 'config.guestFullName', search_option => 'filter_os');
|
||||
$self->add_filter(filters => $filters, label => 'config.uuid', search_option => 'filter_uuid');
|
||||
|
||||
my @properties = ('name', 'runtime.connectionState', 'runtime.powerState', 'config.hardware.device');
|
||||
if (defined($self->{display_description})) {
|
||||
push @properties, 'config.annotation';
|
||||
}
|
||||
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'VirtualMachine', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $values = centreon::vmware::common::generic_performance_values_historic(
|
||||
$self->{connector},
|
||||
$result,
|
||||
[
|
||||
{ label => 'net.received.average', instances => ['*'] },
|
||||
{ label => 'net.transmitted.average', instances => ['*'] }
|
||||
],
|
||||
$self->{connector}->{perfcounter_speriod},
|
||||
sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift},
|
||||
skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1
|
||||
);
|
||||
|
||||
return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1);
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
|
||||
$data->{$entity_value} = {
|
||||
name => $entity_view->{name},
|
||||
connection_state => $entity_view->{'runtime.connectionState'}->val,
|
||||
power_state => $entity_view->{'runtime.powerState'}->val,
|
||||
'config.annotation' => defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : undef,
|
||||
interfaces => {}
|
||||
};
|
||||
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
next if (centreon::vmware::common::is_running(power => $entity_view->{'runtime.powerState'}->val) == 0);
|
||||
|
||||
foreach (@{$entity_view->{'config.hardware.device'}}) {
|
||||
next if (! $_->isa('VirtualEthernetCard'));
|
||||
|
||||
# KBps
|
||||
my $traffic_in = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{ $self->{connector}->{perfcounter_cache}->{'net.received.average'}->{key} . ":" . $_->{key} })) * 1024 * 8;
|
||||
my $traffic_out = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{ $self->{connector}->{perfcounter_cache}->{'net.transmitted.average'}->{key} . ":" . $_->{key} })) * 1024 * 8;
|
||||
|
||||
$data->{$entity_value}->{interfaces}->{ $_->{deviceInfo}->{label} }->{'net.received.average'} = $traffic_in;
|
||||
$data->{$entity_value}->{interfaces}->{ $_->{deviceInfo}->{label} }->{'net.transmitted.average'} = $traffic_out;
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,97 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdservicehost;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'servicehost';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter');
|
||||
my @properties = ('name', 'runtime.connectionState', 'runtime.inMaintenanceMode', 'configManager.serviceSystem');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my %host_names = ();
|
||||
my @host_array = ();
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
|
||||
$data->{$entity_value} = { name => $entity_view->{name},
|
||||
state => $entity_view->{'runtime.connectionState'}->val,
|
||||
inMaintenanceMode => $entity_view->{'runtime.inMaintenanceMode'},
|
||||
services => [],
|
||||
};
|
||||
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
next if (centreon::vmware::common::is_maintenance(maintenance => $entity_view->{'runtime.inMaintenanceMode'}) == 0);
|
||||
|
||||
if (defined($entity_view->{'configManager.serviceSystem'})) {
|
||||
push @host_array, $entity_view->{'configManager.serviceSystem'};
|
||||
$host_names{$entity_view->{'configManager.serviceSystem'}->{value}} = $entity_value;
|
||||
}
|
||||
}
|
||||
|
||||
if (scalar(@host_array) == 0) {
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
return ;
|
||||
}
|
||||
|
||||
@properties = ('serviceInfo');
|
||||
my $result2 = centreon::vmware::common::get_views($self->{connector}, \@host_array, \@properties);
|
||||
return if (!defined($result2));
|
||||
|
||||
foreach my $entity (@$result2) {
|
||||
my $host_id = $host_names{$entity->{mo_ref}->{value}};
|
||||
|
||||
foreach my $service (@{$entity->{serviceInfo}->{service}}) {
|
||||
push @{$data->{$host_id}->{services}}, { key => $service->{key}, label => $service->{label}, policy => $service->{policy}, running => $service->{running} };
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,97 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdsnapshotvm;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'snapshotvm';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: vm hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'vm_hostname', is_regexp => 'filter');
|
||||
$self->add_filter(filters => $filters, label => 'config.annotation', search_option => 'filter_description');
|
||||
$self->add_filter(filters => $filters, label => 'config.guestFullName', search_option => 'filter_os');
|
||||
$self->add_filter(filters => $filters, label => 'config.uuid', search_option => 'filter_uuid');
|
||||
|
||||
my @properties = ('snapshot.rootSnapshotList', 'name', 'runtime.connectionState', 'runtime.powerState');
|
||||
if (defined($self->{check_consolidation}) == 1) {
|
||||
push @properties, 'runtime.consolidationNeeded';
|
||||
}
|
||||
if (defined($self->{display_description})) {
|
||||
push @properties, 'config.annotation';
|
||||
}
|
||||
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'VirtualMachine', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my %vm_consolidate = ();
|
||||
my %vm_errors = (warning => {}, critical => {});
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
|
||||
$data->{$entity_value} = {
|
||||
name => $entity_view->{name},
|
||||
connection_state => $entity_view->{'runtime.connectionState'}->val,
|
||||
power_state => $entity_view->{'runtime.powerState'}->val,
|
||||
'config.annotation' => defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : undef,
|
||||
snapshosts => [],
|
||||
};
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
|
||||
if (defined($self->{check_consolidation}) && defined($entity_view->{'runtime.consolidationNeeded'}) && $entity_view->{'runtime.consolidationNeeded'} =~ /^true|1$/i) {
|
||||
$data->{$entity_value}->{consolidation_needed} = 1;
|
||||
}
|
||||
|
||||
next if (!defined($entity_view->{'snapshot.rootSnapshotList'}));
|
||||
|
||||
foreach my $snapshot (@{$entity_view->{'snapshot.rootSnapshotList'}}) {
|
||||
# 2012-09-21T14:16:17.540469Z
|
||||
push @{$data->{$entity_value}->{snapshosts}}, { name => $snapshot->name, description => $snapshot->description, create_time => $snapshot->createTime };
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,89 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdstatuscluster;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'statuscluster';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{cluster_name}) && $options{arguments}->{cluster_name} eq '') {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => 'Argument error: cluster name cannot be null');
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $vsan_cluster_health;
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'cluster_name', is_regexp => 'filter');
|
||||
my @properties = ('name', 'summary.overallStatus', 'configuration');
|
||||
if ($self->is_vsan_enabled()) {
|
||||
$vsan_cluster_health = centreon::vmware::common::vsan_create_mo_view(
|
||||
vsan_vim => $self->{connector}->{vsan_vim},
|
||||
type => 'VsanVcClusterHealthSystem',
|
||||
value => 'vsan-cluster-health-system',
|
||||
);
|
||||
push @properties, 'configurationEx';
|
||||
}
|
||||
my $views = centreon::vmware::common::search_entities(command => $self, view_type => 'ClusterComputeResource', properties => \@properties, filter => $filters);
|
||||
return if (!defined($views));
|
||||
|
||||
my $data = {};
|
||||
foreach my $view (@$views) {
|
||||
my $entity_value = $view->{mo_ref}->{value};
|
||||
$data->{$entity_value} = {
|
||||
name => $view->{name},
|
||||
overall_status => $view->{'summary.overallStatus'}->val,
|
||||
ha_enabled => (defined($view->{configuration}->{dasConfig}->{enabled}) && $view->{configuration}->{dasConfig}->{enabled} =~ /^1|true/i) ? 'true' : 'false',
|
||||
drs_enabled => (defined($view->{configuration}->{drsConfig}->{enabled}) && $view->{configuration}->{drsConfig}->{enabled} =~ /^1|true/i) ? 'true' : 'false'
|
||||
};
|
||||
|
||||
if (defined($view->{configurationEx}->{vsanConfigInfo}) && $view->{configurationEx}->{vsanConfigInfo}->enabled == 1) {
|
||||
my $summary = $vsan_cluster_health->VsanQueryVcClusterHealthSummary(
|
||||
cluster => $view,
|
||||
includeObjUuids => 'false',
|
||||
fetchFromCache => 'false',
|
||||
fields => ['clusterStatus']
|
||||
);
|
||||
$data->{$entity_value}->{vsan_cluster_status} = $summary->clusterStatus->status;
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,68 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdstatushost;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'statushost';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter');
|
||||
my @properties = ('name', 'summary.overallStatus', 'runtime.connectionState');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
$data->{$entity_value} = { name => $entity_view->{name}, state => $entity_view->{'runtime.connectionState'}->val };
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
|
||||
$data->{$entity_value}->{overall_status} = $entity_view->{'summary.overallStatus'}->val;
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,82 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdstatusvm;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'statusvm';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: vm hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'vm_hostname', is_regexp => 'filter');
|
||||
$self->add_filter(filters => $filters, label => 'config.annotation', search_option => 'filter_description');
|
||||
$self->add_filter(filters => $filters, label => 'config.guestFullName', search_option => 'filter_os');
|
||||
$self->add_filter(filters => $filters, label => 'config.uuid', search_option => 'filter_uuid');
|
||||
|
||||
my @properties = ('name', 'summary.overallStatus', 'runtime.connectionState', 'runtime.powerState');
|
||||
if (defined($self->{display_description})) {
|
||||
push @properties, 'config.annotation';
|
||||
}
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'VirtualMachine', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
|
||||
$data->{$entity_value} = {
|
||||
name => $entity_view->{name},
|
||||
connection_state => $entity_view->{'runtime.connectionState'}->val,
|
||||
power_state => $entity_view->{'runtime.powerState'}->val,
|
||||
'config.annotation' => defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : undef,
|
||||
};
|
||||
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
|
||||
$data->{$entity_value}->{overall_status} = $entity_view->{'summary.overallStatus'}->val;
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,134 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdstoragehost;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'storagehost';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter');
|
||||
my @properties = ('name', 'runtime.connectionState', 'runtime.inMaintenanceMode', 'configManager.storageSystem');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my %host_names = ();
|
||||
my @host_array = ();
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
|
||||
$data->{$entity_value} = {
|
||||
name => $entity_view->{name},
|
||||
state => $entity_view->{'runtime.connectionState'}->val,
|
||||
inMaintenanceMode => $entity_view->{'runtime.inMaintenanceMode'},
|
||||
};
|
||||
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
next if (centreon::vmware::common::is_maintenance(maintenance => $entity_view->{'runtime.inMaintenanceMode'}) == 0);
|
||||
|
||||
if (defined($entity_view->{'configManager.storageSystem'})) {
|
||||
push @host_array, $entity_view->{'configManager.storageSystem'};
|
||||
$host_names{ $entity_view->{'configManager.storageSystem'}->{value} } = $entity_value;
|
||||
}
|
||||
}
|
||||
|
||||
if (scalar(@host_array) == 0) {
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
return ;
|
||||
}
|
||||
|
||||
@properties = ('storageDeviceInfo');
|
||||
my $result2 = centreon::vmware::common::get_views($self->{connector}, \@host_array, \@properties);
|
||||
return if (!defined($result2));
|
||||
|
||||
foreach my $entity (@$result2) {
|
||||
my $host_id = $host_names{ $entity->{mo_ref}->{value} };
|
||||
|
||||
if (defined($entity->storageDeviceInfo->hostBusAdapter)) {
|
||||
$data->{$host_id}->{adapters} = [];
|
||||
foreach my $dev (@{$entity->storageDeviceInfo->hostBusAdapter}) {
|
||||
push @{$data->{$host_id}->{adapters}}, {
|
||||
name => $dev->device,
|
||||
status => lc($dev->status)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (defined($entity->storageDeviceInfo->scsiLun)) {
|
||||
$data->{$host_id}->{luns} = [];
|
||||
foreach my $scsi (@{$entity->storageDeviceInfo->scsiLun}) {
|
||||
my $name = $scsi->deviceName;
|
||||
if (defined($scsi->{displayName})) {
|
||||
$name = $scsi->displayName;
|
||||
} elsif (defined($scsi->{canonicalName})) {
|
||||
$name = $scsi->canonicalName;
|
||||
}
|
||||
|
||||
push @{$data->{$host_id}->{luns}}, {
|
||||
name => $name,
|
||||
operational_states => $scsi->operationalState
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (defined($entity->storageDeviceInfo->{multipathInfo})) {
|
||||
$data->{$host_id}->{paths} = [];
|
||||
foreach my $lun (@{$entity->storageDeviceInfo->multipathInfo->lun}) {
|
||||
foreach my $path (@{$lun->path}) {
|
||||
my $state = $path->pathState;
|
||||
$state = $path->state if (defined($path->{state}));
|
||||
push @{$data->{$host_id}->{paths}}, {
|
||||
name => $path->name,
|
||||
state => lc($state)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,87 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdswaphost;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'swaphost';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{connector}->{perfcounter_speriod} > 0)) {
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter');
|
||||
my @properties = ('name', 'runtime.connectionState');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $values = centreon::vmware::common::generic_performance_values_historic($self->{connector},
|
||||
$result,
|
||||
[{'label' => 'mem.swapinRate.average', 'instances' => ['']},
|
||||
{'label' => 'mem.swapoutRate.average', 'instances' => ['']}],
|
||||
$self->{connector}->{perfcounter_speriod},
|
||||
sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift},
|
||||
skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1);
|
||||
return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1);
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
$data->{$entity_value} = { name => $entity_view->{name}, state => $entity_view->{'runtime.connectionState'}->val };
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
|
||||
# KBps
|
||||
my $swap_in = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.swapinRate.average'}->{'key'} . ":"})) * 1024;
|
||||
my $swap_out = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.swapoutRate.average'}->{'key'} . ":"})) * 1024;
|
||||
|
||||
$data->{$entity_value}->{'mem.swapinRate.average'} = $swap_in;
|
||||
$data->{$entity_value}->{'mem.swapoutRate.average'} = $swap_out;
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,103 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdswapvm;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'swapvm';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: vm hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{connector}->{perfcounter_speriod} > 0)) {
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'vm_hostname', is_regexp => 'filter');
|
||||
$self->add_filter(filters => $filters, label => 'config.annotation', search_option => 'filter_description');
|
||||
$self->add_filter(filters => $filters, label => 'config.guestFullName', search_option => 'filter_os');
|
||||
$self->add_filter(filters => $filters, label => 'config.uuid', search_option => 'filter_uuid');
|
||||
|
||||
my @properties = ('name', 'runtime.connectionState', 'runtime.powerState');
|
||||
if (defined($self->{display_description})) {
|
||||
push @properties, 'config.annotation';
|
||||
}
|
||||
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'VirtualMachine', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $values = centreon::vmware::common::generic_performance_values_historic($self->{connector},
|
||||
$result,
|
||||
[{label => 'mem.swapinRate.average', instances => ['']},
|
||||
{label => 'mem.swapoutRate.average', instances => ['']}],
|
||||
$self->{connector}->{perfcounter_speriod},
|
||||
sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift},
|
||||
skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1);
|
||||
return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1);
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
|
||||
$data->{$entity_value} = {
|
||||
name => $entity_view->{name},
|
||||
connection_state => $entity_view->{'runtime.connectionState'}->val,
|
||||
power_state => $entity_view->{'runtime.powerState'}->val,
|
||||
'config.annotation' => defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : undef,
|
||||
};
|
||||
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
next if (centreon::vmware::common::is_running(power => $entity_view->{'runtime.powerState'}->val) == 0);
|
||||
|
||||
# KBps
|
||||
my $swap_in = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.swapinRate.average'}->{'key'} . ":"})) * 1024;
|
||||
my $swap_out = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.swapoutRate.average'}->{'key'} . ":"})) * 1024;
|
||||
|
||||
$data->{$entity_value}->{'mem.swapinRate.average'} = $swap_in;
|
||||
$data->{$entity_value}->{'mem.swapoutRate.average'} = $swap_out;
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,89 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdthinprovisioningvm;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'thinprovisioningvm';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: vm hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'vm_hostname', is_regexp => 'filter');
|
||||
$self->add_filter(filters => $filters, label => 'config.annotation', search_option => 'filter_description');
|
||||
$self->add_filter(filters => $filters, label => 'config.guestFullName', search_option => 'filter_os');
|
||||
$self->add_filter(filters => $filters, label => 'config.uuid', search_option => 'filter_uuid');
|
||||
|
||||
my @properties = ('name', 'config.hardware.device', 'runtime.connectionState', 'runtime.powerState');
|
||||
if (defined($self->{display_description})) {
|
||||
push @properties, 'config.annotation';
|
||||
}
|
||||
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'VirtualMachine', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
|
||||
$data->{$entity_value} = {
|
||||
name => $entity_view->{name},
|
||||
connection_state => $entity_view->{'runtime.connectionState'}->val,
|
||||
power_state => $entity_view->{'runtime.powerState'}->val,
|
||||
'config.annotation' => defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : undef,
|
||||
disks => [],
|
||||
};
|
||||
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
|
||||
foreach (@{$entity_view->{'config.hardware.device'}}) {
|
||||
if ($_->isa('VirtualDisk')) {
|
||||
next if (!defined($_->{backing}->{thinProvisioned}));
|
||||
push @{$data->{$entity_value}->{disks}}, { thin_provisioned => $_->{backing}->{thinProvisioned}, name => $_->{backing}->{fileName} };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,86 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdtimehost;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'timehost';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter');
|
||||
my @properties = ('name', 'configManager.dateTimeSystem', 'runtime.connectionState');
|
||||
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $data = {};
|
||||
my @host_array = ();
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
$data->{$entity_value} = { name => $entity_view->{name}, state => $entity_view->{'runtime.connectionState'}->val };
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
|
||||
if (defined($entity_view->{'configManager.dateTimeSystem'})) {
|
||||
push @host_array, $entity_view->{'configManager.dateTimeSystem'};
|
||||
}
|
||||
}
|
||||
|
||||
@properties = ();
|
||||
my $result2 = centreon::vmware::common::get_views($self->{connector}, \@host_array, \@properties);
|
||||
return if (!defined($result2));
|
||||
|
||||
foreach my $entity_view (@$result) {
|
||||
my $host_dts_value = $entity_view->{'configManager.dateTimeSystem'}->{value};
|
||||
foreach my $host_dts_view (@$result2) {
|
||||
if ($host_dts_view->{mo_ref}->{value} eq $host_dts_value) {
|
||||
$data->{$entity_view->{mo_ref}->{value}}->{current_time} = $host_dts_view->QueryDateTime();
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,95 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdtoolsvm;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'toolsvm';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: vm hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub display_verbose {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{manager}->{output}->output_add(long_msg => $options{label});
|
||||
foreach my $vm (sort keys %{$options{vms}}) {
|
||||
my $prefix = $vm;
|
||||
if ($options{vms}->{$vm} ne '') {
|
||||
$prefix .= ' [' . centreon::vmware::common::strip_cr(value => $options{vms}->{$vm}) . ']';
|
||||
}
|
||||
$self->{manager}->{output}->output_add(long_msg => ' ' . $prefix);
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'vm_hostname', is_regexp => 'filter');
|
||||
$self->add_filter(filters => $filters, label => 'config.annotation', search_option => 'filter_description');
|
||||
$self->add_filter(filters => $filters, label => 'config.guestFullName', search_option => 'filter_os');
|
||||
$self->add_filter(filters => $filters, label => 'config.uuid', search_option => 'filter_uuid');
|
||||
|
||||
my @properties = ('name', 'summary.guest.toolsStatus', 'runtime.connectionState', 'runtime.powerState');
|
||||
if (defined($self->{display_description})) {
|
||||
push @properties, 'config.annotation';
|
||||
}
|
||||
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'VirtualMachine', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
|
||||
$data->{$entity_value} = {
|
||||
name => $entity_view->{name},
|
||||
connection_state => $entity_view->{'runtime.connectionState'}->val,
|
||||
power_state => $entity_view->{'runtime.powerState'}->val,
|
||||
'config.annotation' => defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : undef,
|
||||
};
|
||||
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
$data->{$entity_value}->{tools_status} = defined($entity_view->{'summary.guest.toolsStatus'}) ? $entity_view->{'summary.guest.toolsStatus'}->val : undef;
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,67 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmduptimehost;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'uptimehost';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname cannot be null");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter');
|
||||
my @properties = ('name', 'runtime.bootTime', 'runtime.connectionState');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
$data->{$entity_value} = { name => $entity_view->{name}, state => $entity_view->{'runtime.connectionState'}->val };
|
||||
next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0);
|
||||
|
||||
$data->{$entity_value}->{boot_time} = $entity_view->{'runtime.bootTime'};
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,82 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdvmoperationcluster;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'vmoperationcluster';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{cluster}) && $options{arguments}->{cluster} eq "") {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: cluster cannot be null");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (!($self->{connector}->{perfcounter_speriod} > 0)) {
|
||||
centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters");
|
||||
return ;
|
||||
}
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'cluster', is_regexp => 'filter');
|
||||
my @properties = ('name');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'ClusterComputeResource', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $values = centreon::vmware::common::generic_performance_values_historic($self->{connector},
|
||||
$result,
|
||||
[{'label' => 'vmop.numVMotion.latest', 'instances' => ['']},
|
||||
{'label' => 'vmop.numSVMotion.latest', 'instances' => ['']},
|
||||
{'label' => 'vmop.numClone.latest', 'instances' => ['']}],
|
||||
$self->{connector}->{perfcounter_speriod},
|
||||
sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift},
|
||||
skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1);
|
||||
return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1);
|
||||
|
||||
my $data = {};
|
||||
foreach my $entity_view (@$result) {
|
||||
my $entity_value = $entity_view->{mo_ref}->{value};
|
||||
$data->{$entity_value} = { name => centreon::vmware::common::substitute_name(value => $entity_view->{name}) };
|
||||
$data->{$entity_value}->{'vmop.numVMotion.latest'} = $values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'vmop.numVMotion.latest'}->{key} . ":"};
|
||||
$data->{$entity_value}->{'vmop.numSVMotion.latest'} = $values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'vmop.numSVMotion.latest'}->{key} . ":"};
|
||||
$data->{$entity_value}->{'vmop.numClone.latest'} = $values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'vmop.numClone.latest'}->{key} . ":"};
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,106 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::cmdvsanclusterusage;
|
||||
|
||||
use base qw(centreon::vmware::cmdbase);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::common;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(%options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{commandName} = 'vsanclusterusage';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{arguments}->{cluster_name}) && $options{arguments}->{cluster_name} eq '') {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: cluster name cannot be null");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (!$self->is_vsan_enabled()) {
|
||||
centreon::vmware::common::set_response(code => 100, short_message => 'Vsan is not enabled in vmware connector');
|
||||
return ;
|
||||
}
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'cluster_name', is_regexp => 'filter');
|
||||
my @properties = ('name', 'configurationEx');
|
||||
my $views = centreon::vmware::common::search_entities(command => $self, view_type => 'ComputeResource', properties => \@properties, filter => $filters);
|
||||
return if (!defined($views));
|
||||
|
||||
my $vsan_performance_mgr = centreon::vmware::common::vsan_create_mo_view(
|
||||
vsan_vim => $self->{connector}->{vsan_vim},
|
||||
type => 'VsanPerformanceManager',
|
||||
value => 'vsan-performance-manager',
|
||||
);
|
||||
|
||||
my $interval_sec = $self->{connector}->{perfcounter_speriod};
|
||||
if (defined($self->{sampling_period}) && $self->{sampling_period} ne '') {
|
||||
$interval_sec = $self->{sampling_period};
|
||||
}
|
||||
|
||||
my $data = {};
|
||||
foreach my $view (@$views) {
|
||||
next if (!defined($view->{configurationEx}->{vsanConfigInfo}) || $view->{configurationEx}->{vsanConfigInfo}->enabled != 1);
|
||||
|
||||
my $entity_value = $view->{mo_ref}->{value};
|
||||
my $uuid = $view->{configurationEx}->{vsanConfigInfo}->{defaultConfig}->{uuid};
|
||||
my $result = centreon::vmware::common::vsan_get_performances(
|
||||
vsan_performance_mgr => $vsan_performance_mgr,
|
||||
cluster => $view,
|
||||
entityRefId => 'cluster-domcompmgr:*',
|
||||
labels => [
|
||||
'iopsRead',
|
||||
'iopsWrite',
|
||||
'congestion', # number
|
||||
'latencyAvgRead', # time_ms
|
||||
'latencyAvgWrite', # time_ms
|
||||
'oio', # outstanding IO (number),
|
||||
'throughputRead', # rate_bytes
|
||||
'throughputWrite', # rate_bytes
|
||||
],
|
||||
interval => $interval_sec,
|
||||
time_shift => $self->{time_shift}
|
||||
);
|
||||
$data->{$entity_value} = {
|
||||
name => $view->{name},
|
||||
cluster_domcompmgr => {
|
||||
%{$result->{'cluster-domcompmgr:' . $uuid}}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,797 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::common;
|
||||
|
||||
use warnings;
|
||||
use strict;
|
||||
use Data::Dumper;
|
||||
use VMware::VIRuntime;
|
||||
use VMware::VILib;
|
||||
use ZMQ::LibZMQ4;
|
||||
use ZMQ::Constants qw(:all);
|
||||
use JSON::XS;;
|
||||
|
||||
my $manager_display = {};
|
||||
my $manager_response = {};
|
||||
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
|
||||
|
||||
sub set_response {
|
||||
my (%options) = @_;
|
||||
|
||||
$manager_response->{code} = $options{code} if (defined($options{code}));
|
||||
$manager_response->{short_message} = $options{short_message} if (defined($options{short_message}));
|
||||
$manager_response->{extra_message} = $options{extra_message} if (defined($options{extra_message}));
|
||||
$manager_response->{identity} = $options{identity} if (defined($options{identity}));
|
||||
$manager_response->{data} = $options{data} if (defined($options{data}));
|
||||
}
|
||||
|
||||
sub init_response {
|
||||
my (%options) = @_;
|
||||
|
||||
$manager_response->{code} = 0;
|
||||
$manager_response->{vmware_connector_version} = '3.2.5';
|
||||
$manager_response->{short_message} = 'OK';
|
||||
$manager_response->{extra_message} = '';
|
||||
$manager_response->{identity} = $options{identity} if (defined($options{identity}));
|
||||
$manager_response->{data} = {};
|
||||
}
|
||||
|
||||
sub free_response {
|
||||
$manager_response = {};
|
||||
}
|
||||
|
||||
sub response {
|
||||
my (%options) = @_;
|
||||
|
||||
my $response_str = '';
|
||||
if (defined($options{force_response})) {
|
||||
$response_str = $options{force_response};
|
||||
} else {
|
||||
eval {
|
||||
$response_str = JSON::XS->new->utf8->encode($manager_response);
|
||||
};
|
||||
if ($@) {
|
||||
$response_str = '{ "code": -1, "short_message": "Cannot encode result" }';
|
||||
}
|
||||
}
|
||||
|
||||
if (defined($options{reinit})) {
|
||||
my $context = zmq_init();
|
||||
$options{endpoint} = zmq_socket($context, ZMQ_DEALER);
|
||||
zmq_connect($options{endpoint}, $options{reinit});
|
||||
# we wait 10 seconds after. If not there is a problem... so we can quit
|
||||
# dialog from vsphere response to router
|
||||
zmq_setsockopt($options{endpoint}, ZMQ_LINGER, 10000);
|
||||
}
|
||||
if (defined($options{identity})) {
|
||||
my $msg = zmq_msg_init_data($options{identity});
|
||||
zmq_msg_send($msg, $options{endpoint}, $flag);
|
||||
zmq_msg_close($msg);
|
||||
}
|
||||
my $msg = zmq_msg_init_data($options{token} . " " . $response_str);
|
||||
zmq_msg_send($msg, $options{endpoint}, ZMQ_NOBLOCK);
|
||||
zmq_msg_close($msg);
|
||||
}
|
||||
|
||||
sub vmware_error {
|
||||
my ($obj_vmware, $lerror) = @_;
|
||||
|
||||
set_response(extra_message => $lerror);
|
||||
$obj_vmware->{logger}->writeLogError("'" . $obj_vmware->{whoaim} . "' $lerror");
|
||||
if ($lerror =~ /NoPermissionFault/i) {
|
||||
set_response(code => -1, short_message => 'VMWare error: not enought permissions');
|
||||
} else {
|
||||
set_response(code => -1, short_message => 'VMWare error (verbose mode for more details)');
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub connect_vsphere {
|
||||
my (%options) = @_;
|
||||
|
||||
$options{logger}->writeLogInfo("'$options{whoaim}' Vsphere connection in progress");
|
||||
eval {
|
||||
$SIG{ALRM} = sub { die('TIMEOUT'); };
|
||||
alarm($options{connect_timeout});
|
||||
$options{connector}->{session} = Vim->new(service_url => $options{url});
|
||||
$options{connector}->{session}->login(
|
||||
user_name => $options{username},
|
||||
password => $options{password}
|
||||
);
|
||||
|
||||
$options{connector}->{service_url} = $options{url};
|
||||
#$options{connector}->{session}->save_session(session_file => '/tmp/plop.save');
|
||||
#$options{connector}->{session}->unset_logout_on_disconnect();
|
||||
|
||||
get_vsan_vim(%options) if ($options{vsan_enabled} == 1);
|
||||
|
||||
alarm(0);
|
||||
};
|
||||
if ($@) {
|
||||
$options{logger}->writeLogError("'$options{whoaim}' No response from VirtualCenter server") if($@ =~ /TIMEOUT/);
|
||||
$options{logger}->writeLogError("'$options{whoaim}' You need to upgrade HTTP::Message!") if($@ =~ /HTTP::Message/);
|
||||
$options{logger}->writeLogError("'$options{whoaim}' Login to VirtualCenter server failed: $@");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub heartbeat {
|
||||
my (%options) = @_;
|
||||
my $stime;
|
||||
|
||||
eval {
|
||||
$stime = $options{connector}->{session}->get_service_instance()->CurrentTime();
|
||||
$options{connector}->{keeper_session_time} = time();
|
||||
};
|
||||
if ($@) {
|
||||
$options{connector}->{logger}->writeLogError("$@");
|
||||
# Try a second time
|
||||
eval {
|
||||
$stime = $options{connector}->{session}->get_service_instance()->CurrentTime();
|
||||
$options{connector}->{keeper_session_time} = time();
|
||||
};
|
||||
if ($@) {
|
||||
$options{connector}->{logger}->writeLogError("$@");
|
||||
$options{connector}->{logger}->writeLogError("'" . $options{connector}->{whoaim} . "' Ask a new connection");
|
||||
# Ask a new connection
|
||||
$options{connector}->{last_time_check} = time();
|
||||
}
|
||||
}
|
||||
|
||||
$options{connector}->{logger}->writeLogInfo("'" . $options{connector}->{whoaim} . "' Get current time = " . Data::Dumper::Dumper($stime));
|
||||
}
|
||||
|
||||
sub simplify_number {
|
||||
my ($number, $cnt) = @_;
|
||||
$cnt = 2 if (!defined($cnt));
|
||||
return sprintf("%.${cnt}f", "$number");
|
||||
}
|
||||
|
||||
sub convert_number {
|
||||
my ($number) = shift(@_);
|
||||
# Avoid error counter empty. But should manage it in code the 'undef'.
|
||||
$number = 0 if (!defined($number));
|
||||
$number =~ s/\,/\./;
|
||||
return $number;
|
||||
}
|
||||
|
||||
sub get_views {
|
||||
my $obj_vmware = shift;
|
||||
my $results;
|
||||
|
||||
eval {
|
||||
$results = $obj_vmware->{session}->get_views(mo_ref_array => $_[0], properties => $_[1]);
|
||||
};
|
||||
if ($@) {
|
||||
vmware_error($obj_vmware, $@);
|
||||
return undef;
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
sub get_view {
|
||||
my $obj_vmware = shift;
|
||||
my $results;
|
||||
|
||||
eval {
|
||||
$results = $obj_vmware->{session}->get_view(mo_ref => $_[0], properties => $_[1]);
|
||||
};
|
||||
if ($@) {
|
||||
vmware_error($obj_vmware, $@);
|
||||
return undef;
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
sub search_in_datastore {
|
||||
my (%options) = @_;
|
||||
my $result;
|
||||
|
||||
my $files = FileQueryFlags->new(
|
||||
fileSize => 1,
|
||||
fileType => 1,
|
||||
modification => 1,
|
||||
fileOwner => 1
|
||||
);
|
||||
my $hostdb_search_spec = HostDatastoreBrowserSearchSpec->new(
|
||||
details => $files,
|
||||
searchCaseInsensitive => $options{searchCaseInsensitive},
|
||||
matchPattern => $options{matchPattern},
|
||||
query => $options{query}
|
||||
);
|
||||
eval {
|
||||
$result = $options{browse_ds}->SearchDatastoreSubFolders(
|
||||
datastorePath => $options{ds_name},
|
||||
searchSpec => $hostdb_search_spec
|
||||
);
|
||||
};
|
||||
if ($@) {
|
||||
return (undef, $@) if (defined($options{return}) && $options{return} == 1);
|
||||
vmware_error($options{connector}, $@);
|
||||
return undef;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
sub get_perf_metric_ids {
|
||||
my (%options) = @_;
|
||||
my $filtered_list = [];
|
||||
|
||||
foreach (@{$options{metrics}}) {
|
||||
if (defined($options{connector}->{perfcounter_cache}->{$_->{label}})) {
|
||||
if ($options{interval} != 20 && $options{connector}->{perfcounter_cache}->{$_->{label}}{level} > $options{connector}->{sampling_periods}->{$options{interval}}->{level}) {
|
||||
set_response(
|
||||
code => -1,
|
||||
short_message => sprintf(
|
||||
"Cannot get counter '%s' for the sampling period '%s' (counter level: %s, sampling level: %s)",
|
||||
$_->{label}, $options{interval},
|
||||
$options{connector}->{perfcounter_cache}->{$_->{label}}{level},
|
||||
$options{connector}->{sampling_periods}->{$options{interval}}->{level}
|
||||
)
|
||||
);
|
||||
return undef;
|
||||
}
|
||||
foreach my $instance (@{$_->{instances}}) {
|
||||
my $metric = PerfMetricId->new(
|
||||
counterId => $options{connector}->{perfcounter_cache}->{$_->{label}}{key},
|
||||
instance => $instance
|
||||
);
|
||||
push @$filtered_list, $metric;
|
||||
}
|
||||
} else {
|
||||
$options{connector}->{logger}->writeLogError("Metric '" . $_->{label} . "' unavailable.");
|
||||
set_response(code => -1, short_message => "Counter doesn't exist. VMware version can be too old.");
|
||||
return undef;
|
||||
}
|
||||
}
|
||||
return $filtered_list;
|
||||
}
|
||||
|
||||
sub performance_builder_specific {
|
||||
my (%options) = @_;
|
||||
|
||||
my $time_shift = defined($options{time_shift}) ? $options{time_shift} : 0;
|
||||
my @perf_query_spec;
|
||||
foreach my $entry (@{$options{metrics}}) {
|
||||
my $perf_metric_ids = get_perf_metric_ids(
|
||||
connector => $options{connector},
|
||||
metrics => $entry->{metrics},
|
||||
interval => $options{interval}
|
||||
);
|
||||
return undef if (!defined($perf_metric_ids));
|
||||
|
||||
my $tstamp = time();
|
||||
my (@t) = gmtime($tstamp - $options{interval} - $time_shift);
|
||||
my $startTime = sprintf(
|
||||
"%04d-%02d-%02dT%02d:%02d:%02dZ",
|
||||
(1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]
|
||||
);
|
||||
(@t) = gmtime($tstamp);
|
||||
my $endTime = sprintf(
|
||||
"%04d-%02d-%02dT%02d:%02d:%02dZ",
|
||||
(1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]
|
||||
);
|
||||
if ($options{interval} == 20) {
|
||||
push @perf_query_spec, PerfQuerySpec->new(
|
||||
entity => $entry->{entity},
|
||||
metricId => $perf_metric_ids,
|
||||
format => 'normal',
|
||||
intervalId => 20,
|
||||
startTime => $startTime,
|
||||
endTime => $endTime
|
||||
);
|
||||
#maxSample => 1);
|
||||
} else {
|
||||
push @perf_query_spec, PerfQuerySpec->new(
|
||||
entity => $entry->{entity},
|
||||
metricId => $perf_metric_ids,
|
||||
format => 'normal',
|
||||
intervalId => $options{interval},
|
||||
startTime => $startTime,
|
||||
endTime => $endTime
|
||||
);
|
||||
#maxSample => 1);
|
||||
}
|
||||
}
|
||||
|
||||
return $options{connector}->{perfmanager_view}->QueryPerf(querySpec => \@perf_query_spec);
|
||||
}
|
||||
|
||||
sub performance_builder_global {
|
||||
my (%options) = @_;
|
||||
|
||||
my $time_shift = defined($options{time_shift}) ? $options{time_shift} : 0;
|
||||
my @perf_query_spec;
|
||||
my $perf_metric_ids = get_perf_metric_ids(
|
||||
connector => $options{connector},
|
||||
metrics => $options{metrics},
|
||||
interval => $options{interval}
|
||||
);
|
||||
return undef if (!defined($perf_metric_ids));
|
||||
|
||||
my $tstamp = time();
|
||||
my (@t) = gmtime($tstamp - $options{interval} - $time_shift);
|
||||
my $startTime = sprintf(
|
||||
"%04d-%02d-%02dT%02d:%02d:%02dZ",
|
||||
(1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]
|
||||
);
|
||||
(@t) = gmtime($tstamp);
|
||||
my $endTime = sprintf(
|
||||
"%04d-%02d-%02dT%02d:%02d:%02dZ",
|
||||
(1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]
|
||||
);
|
||||
|
||||
foreach (@{$options{views}}) {
|
||||
if ($options{interval} == 20) {
|
||||
push @perf_query_spec, PerfQuerySpec->new(
|
||||
entity => $_,
|
||||
metricId => $perf_metric_ids,
|
||||
format => 'normal',
|
||||
intervalId => 20,
|
||||
startTime => $startTime,
|
||||
endTime => $endTime
|
||||
);
|
||||
#maxSample => 1);
|
||||
} else {
|
||||
push @perf_query_spec, PerfQuerySpec->new(
|
||||
entity => $_,
|
||||
metricId => $perf_metric_ids,
|
||||
format => 'normal',
|
||||
intervalId => $options{interval},
|
||||
startTime => $startTime,
|
||||
endTime => $endTime
|
||||
);
|
||||
#maxSample => 1);
|
||||
}
|
||||
}
|
||||
|
||||
return $options{connector}->{perfmanager_view}->QueryPerf(querySpec => \@perf_query_spec);
|
||||
}
|
||||
|
||||
sub generic_performance_values_historic {
|
||||
my ($obj_vmware, $views, $perfs, $interval, %options) = @_;
|
||||
my $counter = 0;
|
||||
my %results;
|
||||
|
||||
# overload the default sampling choosen
|
||||
if (defined($options{sampling_period}) && $options{sampling_period} ne '') {
|
||||
$interval = $options{sampling_period};
|
||||
}
|
||||
# check sampling period exist (period 20 is not listed)
|
||||
if ($interval != 20 && !defined($obj_vmware->{sampling_periods}->{$interval})) {
|
||||
set_response(code => -1, short_message => sprintf("Sampling period '%s' not managed.", $interval));
|
||||
return undef;
|
||||
}
|
||||
if ($interval != 20 && $obj_vmware->{sampling_periods}->{$interval}->{enabled} != 1) {
|
||||
set_response(code => -1, short_message => sprintf("Sampling period '%s' collection data no enabled.", $interval));
|
||||
return undef;
|
||||
}
|
||||
eval {
|
||||
my $perfdata;
|
||||
|
||||
if (defined($views)) {
|
||||
$perfdata = performance_builder_global(
|
||||
connector => $obj_vmware,
|
||||
views => $views,
|
||||
metrics => $perfs,
|
||||
interval => $interval,
|
||||
time_shift => $options{time_shift}
|
||||
);
|
||||
} else {
|
||||
$perfdata = performance_builder_specific(
|
||||
connector => $obj_vmware,
|
||||
metrics => $perfs,
|
||||
interval => $interval,
|
||||
time_shift => $options{time_shift}
|
||||
);
|
||||
}
|
||||
return undef if (!defined($perfdata));
|
||||
|
||||
if (!$$perfdata[0] || !defined($$perfdata[0]->value)) {
|
||||
set_response(code => -1, short_message => 'Cannot get value for counters (Maybe, object(s) cannot be reached: disconnected, not running, time not synced (see time-host mode),...)');
|
||||
return undef;
|
||||
}
|
||||
foreach my $val (@$perfdata) {
|
||||
foreach (@{$val->{value}}) {
|
||||
if (defined($options{skip_undef_counter}) && $options{skip_undef_counter} == 1 && !defined($_->value)) {
|
||||
$results{$_->id->counterId . ":" . (defined($_->id->instance) ? $_->id->instance : "")} = undef;
|
||||
next;
|
||||
} elsif (!defined($_->value)) {
|
||||
set_response(code => -1, short_message => 'Cannot get value for counters. Maybe there is time sync problem (check the esxd server and the target also)');
|
||||
return undef;
|
||||
}
|
||||
|
||||
my $aggregated_counter_value = 0;
|
||||
foreach my $counter_value (@{$_->value}) {
|
||||
$aggregated_counter_value += $counter_value;
|
||||
}
|
||||
if (scalar(@{$_->value}) > 1) {
|
||||
$aggregated_counter_value /= scalar(@{$_->value});
|
||||
}
|
||||
|
||||
if (defined($options{multiples}) && $options{multiples} == 1) {
|
||||
if (defined($options{multiples_result_by_entity}) && $options{multiples_result_by_entity} == 1) {
|
||||
$results{$val->{entity}->{value}} = {} if (!defined($results{$val->{entity}->{value}}));
|
||||
$results{$val->{entity}->{value}}->{$_->id->counterId . ":" . (defined($_->id->instance) ? $_->id->instance : "")} = $aggregated_counter_value;
|
||||
} else {
|
||||
$results{$val->{entity}->{value} . ":" . $_->id->counterId . ":" . (defined($_->id->instance) ? $_->id->instance : "")} = $aggregated_counter_value;
|
||||
}
|
||||
} else {
|
||||
$results{$_->id->counterId . ":" . (defined($_->id->instance) ? $_->id->instance : "")} = $aggregated_counter_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
if ($@) {
|
||||
if ($@ =~ /querySpec.interval.*InvalidArgumentFault/msi) {
|
||||
set_response(
|
||||
code => -1,
|
||||
short_message => sprintf(
|
||||
"Interval '%s' is surely not supported for the managed entity (caller: %s)",
|
||||
$interval,
|
||||
join('--', caller)
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$obj_vmware->{logger}->writeLogError("'" . $obj_vmware->{whoaim} . "' $@");
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
return \%results;
|
||||
}
|
||||
|
||||
sub cache_perf_counters {
|
||||
my $obj_vmware = shift;
|
||||
|
||||
eval {
|
||||
$obj_vmware->{perfmanager_view} = $obj_vmware->{session}->get_view(mo_ref => $obj_vmware->{session}->get_service_content()->perfManager, properties => ['perfCounter', 'historicalInterval']);
|
||||
foreach (@{$obj_vmware->{perfmanager_view}->perfCounter}) {
|
||||
my $label = $_->groupInfo->key . "." . $_->nameInfo->key . "." . $_->rollupType->val;
|
||||
$obj_vmware->{perfcounter_cache}->{$label} = { key => $_->key, unitkey => $_->unitInfo->key, level => $_->level };
|
||||
$obj_vmware->{perfcounter_cache_reverse}->{$_->key} = $label;
|
||||
}
|
||||
|
||||
my $historical_intervals = $obj_vmware->{perfmanager_view}->historicalInterval;
|
||||
$obj_vmware->{sampling_periods} = {};
|
||||
|
||||
foreach (@$historical_intervals) {
|
||||
if ($obj_vmware->{perfcounter_speriod} == -1 || $obj_vmware->{perfcounter_speriod} > $_->samplingPeriod) {
|
||||
$obj_vmware->{perfcounter_speriod} = $_->samplingPeriod;
|
||||
}
|
||||
$obj_vmware->{sampling_periods}->{$_->samplingPeriod} = $_;
|
||||
}
|
||||
|
||||
# Put refresh = 20 (for ESX check)
|
||||
if ($obj_vmware->{perfcounter_speriod} == -1) {
|
||||
$obj_vmware->{perfcounter_speriod} = 20;
|
||||
}
|
||||
};
|
||||
|
||||
if ($@) {
|
||||
$obj_vmware->{logger}->writeLogError("'" . $obj_vmware->{whoaim} . "' $@");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub search_entities {
|
||||
my (%options) = @_;
|
||||
my $properties = ['name'];
|
||||
my $begin_views = [];
|
||||
|
||||
foreach my $scope (['scope_datacenter', 'Datacenter'], ['scope_cluster', 'ClusterComputeResource'], ['scope_host', 'HostSystem']) {
|
||||
if (defined($options{command}->{$scope->[0]}) && $options{command}->{$scope->[0]} ne '') {
|
||||
my $filters = { name => qr/$options{command}->{$scope->[0]}/ };
|
||||
if (scalar(@$begin_views) > 0) {
|
||||
my $temp_views = [];
|
||||
while ((my $view = shift @$begin_views)) {
|
||||
my ($status, $views) = find_entity_views(
|
||||
connector => $options{command}->{connector},
|
||||
view_type => $scope->[1],
|
||||
properties => $properties,
|
||||
filter => $filters,
|
||||
begin_entity => $view,
|
||||
output_message => 0
|
||||
);
|
||||
next if ($status == 0);
|
||||
return undef if ($status == -1);
|
||||
push @$temp_views, @$views;
|
||||
}
|
||||
|
||||
if (scalar(@$temp_views) == 0) {
|
||||
set_response(code => 1, short_message => "Cannot find '$scope->[1]' object");
|
||||
return undef;
|
||||
}
|
||||
push @$begin_views, @$temp_views;
|
||||
} else {
|
||||
my ($status, $views) = find_entity_views(connector => $options{command}->{connector}, view_type => $scope->[1], properties => $properties, filter => $filters);
|
||||
# We quit. No scope find
|
||||
return undef if ($status <= 0);
|
||||
push @$begin_views, @$views;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (scalar(@$begin_views) > 0) {
|
||||
my $results = [];
|
||||
foreach my $view (@$begin_views) {
|
||||
my ($status, $views) = find_entity_views(
|
||||
connector => $options{command}->{connector},
|
||||
view_type => $options{view_type},
|
||||
properties => $options{properties},
|
||||
filter => $options{filter},
|
||||
begin_entity => $view,
|
||||
output_message => 0
|
||||
);
|
||||
next if ($status == 0);
|
||||
return undef if ($status == -1);
|
||||
push @$results, @$views;
|
||||
}
|
||||
if (scalar(@$results) == 0) {
|
||||
set_response(code => 1, short_message => "Cannot find '$options{view_type}' object");
|
||||
return undef;
|
||||
}
|
||||
return $results;
|
||||
} else {
|
||||
my ($status, $views) = find_entity_views(
|
||||
connector => $options{command}->{connector},
|
||||
view_type => $options{view_type},
|
||||
properties => $options{properties},
|
||||
filter => $options{filter},
|
||||
empty_continue => $options{command}->{empty_continue}
|
||||
);
|
||||
return $views;
|
||||
}
|
||||
}
|
||||
|
||||
sub find_entity_views {
|
||||
my (%options) = @_;
|
||||
my $entity_views;
|
||||
|
||||
eval {
|
||||
if (defined($options{begin_entity})) {
|
||||
$entity_views = $options{connector}->{session}->find_entity_views(view_type => $options{view_type}, properties => $options{properties}, filter => $options{filter}, begin_entity => $options{begin_entity});
|
||||
} else {
|
||||
$entity_views = $options{connector}->{session}->find_entity_views(view_type => $options{view_type}, properties => $options{properties}, filter => $options{filter});
|
||||
}
|
||||
};
|
||||
if ($@) {
|
||||
$options{connector}->{logger}->writeLogError("'" . $options{connector}->{whoaim} . "' $@");
|
||||
eval {
|
||||
if (defined($options{begin_entity})) {
|
||||
$entity_views = $options{connector}->{session}->find_entity_views(view_type => $options{view_type}, properties => $options{properties}, filter => $options{filter}, begin_entity => $options{begin_entity});
|
||||
} else {
|
||||
$entity_views = $options{connector}->{session}->find_entity_views(view_type => $options{view_type}, properties => $options{properties}, filter => $options{filter});
|
||||
}
|
||||
};
|
||||
if ($@) {
|
||||
vmware_error($options{connector}, $@);
|
||||
return (-1, undef);
|
||||
}
|
||||
}
|
||||
if (!defined($entity_views) || scalar(@$entity_views) == 0) {
|
||||
my $status = 0;
|
||||
if (defined($options{empty_continue})) {
|
||||
return (1, []);
|
||||
}
|
||||
if (!defined($options{output_message}) || $options{output_message} != 0) {
|
||||
set_response(code => 1, short_message => "Cannot find '$options{view_type}' object");
|
||||
}
|
||||
return (0, undef);
|
||||
}
|
||||
#eval {
|
||||
# $$entity_views[0]->update_view_data(properties => $properties);
|
||||
#};
|
||||
#if ($@) {
|
||||
# writeLogFile("$@");
|
||||
# return undef;
|
||||
#}
|
||||
return (1, $entity_views);
|
||||
}
|
||||
|
||||
sub performance_errors {
|
||||
my ($obj_vmware, $values) = @_;
|
||||
|
||||
# Error counter not available or other from function
|
||||
return 1 if (!defined($values) || scalar(keys(%$values)) <= 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub get_interval_min {
|
||||
my (%options) = @_;
|
||||
|
||||
my $interval = $options{speriod};
|
||||
my $time_shift = defined($options{time_shift}) ? $options{time_shift} : 0;
|
||||
if (defined($options{sampling_period}) && $options{sampling_period} ne '') {
|
||||
$interval = $options{sampling_period};
|
||||
}
|
||||
|
||||
return int(($interval + $time_shift) / 60);
|
||||
}
|
||||
|
||||
sub is_accessible {
|
||||
my (%options) = @_;
|
||||
|
||||
if ($options{accessible} !~ /^true|1$/) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub is_connected {
|
||||
my (%options) = @_;
|
||||
|
||||
if ($options{state} !~ /^connected$/i) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub is_running {
|
||||
my (%options) = @_;
|
||||
|
||||
if ($options{power} !~ /^poweredOn$/i) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub is_maintenance {
|
||||
my (%options) = @_;
|
||||
|
||||
if ($options{maintenance} =~ /^true|1$/) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub substitute_name {
|
||||
my (%options) = @_;
|
||||
|
||||
$options{value} =~ s/%2f/\//g;
|
||||
return $options{value};
|
||||
}
|
||||
|
||||
sub strip_cr {
|
||||
my (%options) = @_;
|
||||
|
||||
$options{value} =~ s/^\s+.*\s+$//mg;
|
||||
$options{value} =~ s/\r//mg;
|
||||
$options{value} =~ s/\n/ -- /mg;
|
||||
return $options{value};
|
||||
}
|
||||
|
||||
sub stats_info {
|
||||
my (%options) = @_;
|
||||
|
||||
my $data = {};
|
||||
foreach my $container (keys %{$options{counters}}) {
|
||||
$data->{$container} = { requests => $options{counters}->{$container} };
|
||||
}
|
||||
set_response(data => $data);
|
||||
}
|
||||
|
||||
#
|
||||
# Vsan
|
||||
#
|
||||
|
||||
sub load_vsanmgmt_binding_files {
|
||||
my (%options) = @_;
|
||||
|
||||
my @stub = ();
|
||||
local $/;
|
||||
for (@{$options{files}}) {
|
||||
open(STUB, $options{path} . '/' . $_) or die $!;
|
||||
push @stub, split /\n####+?\n/, <STUB>;
|
||||
close STUB or die $!;
|
||||
}
|
||||
for (@stub) {
|
||||
my ($package) = /\bpackage\s+(\w+)/;
|
||||
$VIMRuntime::stub_class{$package} = $_ if (defined($package));
|
||||
}
|
||||
eval $VIMRuntime::stub_class{'VimService'};
|
||||
}
|
||||
|
||||
sub get_vsan_vim {
|
||||
my (%options) = @_;
|
||||
|
||||
require URI::URL;
|
||||
my $session_id = $options{connector}->{session}->get_session_id();
|
||||
my $url = URI::URL->new($options{connector}->{session}->get_service_url());
|
||||
my $api_type = $options{connector}->{session}->get_service_content()->about->apiType;
|
||||
|
||||
my $service_url_path = "sdk/vimService";
|
||||
my $path = "vsanHealth";
|
||||
if ($api_type eq "HostAgent") {
|
||||
$service_url_path = "sdk";
|
||||
$path = "vsan";
|
||||
}
|
||||
|
||||
$options{connector}->{vsan_vim} = Vim->new(
|
||||
service_url =>
|
||||
'https://' . $url->host . '/' . $service_url_path,
|
||||
server => $url->host,
|
||||
protocol => "https",
|
||||
path => $path,
|
||||
port => '443'
|
||||
);
|
||||
|
||||
$options{connector}->{vsan_vim}->{vim_service} = VimService->new($options{connector}->{vsan_vim}->{service_url});
|
||||
$options{connector}->{vsan_vim}->{vim_service}->load_session_id($session_id);
|
||||
$options{connector}->{vsan_vim}->unset_logout_on_disconnect;
|
||||
}
|
||||
|
||||
sub vsan_create_mo_view {
|
||||
my (%options) = @_;
|
||||
|
||||
my $moref = ManagedObjectReference->new(
|
||||
type => $options{type},
|
||||
value => $options{value},
|
||||
);
|
||||
my $view_type = $moref->type;
|
||||
my $mo_view = $view_type->new($moref, $options{vsan_vim});
|
||||
return $mo_view;
|
||||
}
|
||||
|
||||
sub vsan_get_performances {
|
||||
my (%options) = @_;
|
||||
|
||||
my $time_shift = defined($options{time_shift}) ? $options{time_shift} : 0;
|
||||
my $tstamp = time();
|
||||
my (@t) = gmtime($tstamp - $options{interval} - $time_shift);
|
||||
my $startTime = sprintf(
|
||||
"%04d-%02d-%02dT%02d:%02d:%02dZ",
|
||||
(1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]
|
||||
);
|
||||
(@t) = gmtime($tstamp);
|
||||
my $endTime = sprintf(
|
||||
"%04d-%02d-%02dT%02d:%02d:%02dZ",
|
||||
(1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]
|
||||
);
|
||||
my $querySpec = VsanPerfQuerySpec->new(
|
||||
entityRefId => $options{entityRefId}, # for example: 'virtual-machine:*'
|
||||
labels => $options{labels}, # for example: ['iopsRead, iopsWrite']
|
||||
startTime => $startTime,
|
||||
endTime => $endTime,
|
||||
);
|
||||
my $values = $options{vsan_performance_mgr}->VsanPerfQueryPerf(
|
||||
querySpecs => [$querySpec],
|
||||
cluster => $options{cluster},
|
||||
);
|
||||
|
||||
my $result = {};
|
||||
foreach (@$values) {
|
||||
$result->{$_->{entityRefId}} = {};
|
||||
foreach my $perf (@{$_->{value}}) {
|
||||
my ($counter, $i) = (0, 0);
|
||||
foreach my $val (split /,/, $perf->{values}) {
|
||||
$counter += $val;
|
||||
$i++;
|
||||
}
|
||||
$result->{$_->{entityRefId}}->{$perf->{metricId}->{label}} = $counter / $i;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,346 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::connector;
|
||||
|
||||
use strict;
|
||||
use VMware::VIRuntime;
|
||||
use VMware::VILib;
|
||||
use JSON::XS;
|
||||
use ZMQ::LibZMQ4;
|
||||
use ZMQ::Constants qw(:all);
|
||||
use File::Basename;
|
||||
use POSIX ":sys_wait_h";
|
||||
use centreon::vmware::common;
|
||||
|
||||
BEGIN {
|
||||
# In new version version of LWP (version 6), the backend is now 'IO::Socket::SSL' (instead Crypt::SSLeay)
|
||||
# it's a hack if you unset that
|
||||
#$ENV{PERL_NET_HTTPS_SSL_SOCKET_CLASS} = "Net::SSL";
|
||||
|
||||
# The option is not omit to verify the certificate chain.
|
||||
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
|
||||
|
||||
eval {
|
||||
# required for new IO::Socket::SSL versions
|
||||
require IO::Socket::SSL;
|
||||
IO::Socket::SSL->import();
|
||||
IO::Socket::SSL::set_ctx_defaults(SSL_verify_mode => 0);
|
||||
};
|
||||
}
|
||||
|
||||
my %handlers = (TERM => {}, HUP => {}, CHLD => {});
|
||||
my ($connector, $backend);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
$connector = {};
|
||||
bless $connector, $class;
|
||||
$connector->set_signal_handlers;
|
||||
|
||||
$connector->{child_proc} = {};
|
||||
$connector->{return_child} = {};
|
||||
$connector->{vsphere_connected} = 0;
|
||||
$connector->{last_time_vsphere} = undef;
|
||||
$connector->{keeper_session_time} = undef;
|
||||
$connector->{last_time_check} = undef;
|
||||
$connector->{perfmanager_view} = undef;
|
||||
$connector->{perfcounter_cache} = {};
|
||||
$connector->{perfcounter_cache_reverse} = {};
|
||||
$connector->{perfcounter_refreshrate} = 20;
|
||||
$connector->{perfcounter_speriod} = -1;
|
||||
$connector->{stop} = 0;
|
||||
$connector->{session} = undef;
|
||||
|
||||
$connector->{modules_registry} = $options{modules_registry};
|
||||
$connector->{logger} = $options{logger};
|
||||
$connector->{whoaim} = $options{name};
|
||||
$connector->{vsan_enabled} = $options{vsan_enabled};
|
||||
$connector->{config_ipc_file} = $options{config}->{ipc_file};
|
||||
$connector->{config_child_timeout} = $options{config}->{timeout};
|
||||
$connector->{config_stop_child_timeout} = $options{config}->{timeout_kill};
|
||||
$connector->{config_vsphere_session_heartbeat} = $options{config}->{refresh_keeper_session};
|
||||
$connector->{config_vsphere_connect_timeout} = $options{config}->{timeout_vsphere};
|
||||
$connector->{config_vsphere_url} = $options{config}->{vsphere_server}->{$options{name}}->{url};
|
||||
$connector->{config_vsphere_user} = $options{config}->{vsphere_server}->{$options{name}}->{username};
|
||||
$connector->{config_vsphere_pass} = $options{config}->{vsphere_server}->{$options{name}}->{password};
|
||||
|
||||
return $connector;
|
||||
}
|
||||
|
||||
sub set_signal_handlers {
|
||||
my $self = shift;
|
||||
|
||||
$SIG{TERM} = \&class_handle_TERM;
|
||||
$handlers{TERM}->{$self} = sub { $self->handle_TERM() };
|
||||
$SIG{HUP} = \&class_handle_HUP;
|
||||
$handlers{HUP}->{$self} = sub { $self->handle_HUP() };
|
||||
$SIG{CHLD} = \&class_handle_CHLD;
|
||||
$handlers{CHLD}->{$self} = sub { $self->handle_CHLD() };
|
||||
}
|
||||
|
||||
sub class_handle_TERM {
|
||||
foreach (keys %{$handlers{TERM}}) {
|
||||
&{$handlers{TERM}->{$_}}();
|
||||
}
|
||||
}
|
||||
|
||||
sub class_handle_HUP {
|
||||
foreach (keys %{$handlers{HUP}}) {
|
||||
&{$handlers{HUP}->{$_}}();
|
||||
}
|
||||
}
|
||||
|
||||
sub class_handle_CHLD {
|
||||
foreach (keys %{$handlers{CHLD}}) {
|
||||
&{$handlers{CHLD}->{$_}}();
|
||||
}
|
||||
}
|
||||
|
||||
sub handle_TERM {
|
||||
my $self = shift;
|
||||
$self->{logger}->writeLogInfo("connector '" . $self->{whoaim} . "' Receiving order to stop...");
|
||||
$self->{stop} = 1;
|
||||
}
|
||||
|
||||
sub handle_HUP {
|
||||
my $self = shift;
|
||||
$self->{logger}->writeLogInfo("connector $$ Receiving order to reload...");
|
||||
# TODO
|
||||
}
|
||||
|
||||
sub handle_CHLD {
|
||||
my $self = shift;
|
||||
my $child_pid;
|
||||
|
||||
while (($child_pid = waitpid(-1, &WNOHANG)) > 0) {
|
||||
$self->{return_child}->{$child_pid} = {status => 1, rtime => time()};
|
||||
}
|
||||
$SIG{CHLD} = \&class_handle_CHLD;
|
||||
}
|
||||
|
||||
sub response_router {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
centreon::vmware::common::init_response(identity => $options{identity});
|
||||
centreon::vmware::common::set_response(code => $options{code}, short_message => $options{msg});
|
||||
centreon::vmware::common::response(token => 'RESPSERVER2', endpoint => $backend);
|
||||
centreon::vmware::common::free_response();
|
||||
}
|
||||
|
||||
sub verify_child {
|
||||
my $self = shift;
|
||||
my $progress = 0;
|
||||
|
||||
# Verify process
|
||||
foreach (keys %{$self->{child_proc}}) {
|
||||
# Check ctime
|
||||
if (defined($self->{return_child}->{$self->{child_proc}->{$_}->{pid}})) {
|
||||
delete $self->{return_child}->{$self->{child_proc}->{$_}->{pid}};
|
||||
delete $self->{child_proc}->{$_};
|
||||
} elsif (time() - $self->{child_proc}->{$_}->{ctime} > $self->{config_child_timeout}) {
|
||||
$self->response_router(
|
||||
code => -1,
|
||||
msg => 'Timeout process',
|
||||
identity => $_
|
||||
);
|
||||
kill('INT', $self->{child_proc}->{$_}->{pid});
|
||||
delete $self->{child_proc}->{$_};
|
||||
} else {
|
||||
$progress++;
|
||||
}
|
||||
}
|
||||
|
||||
# Clean old hash CHILD (security)
|
||||
foreach (keys %{$self->{return_child}}) {
|
||||
if (time() - $self->{return_child}->{$_}->{rtime} > 600) {
|
||||
$self->{logger}->writeLogInfo("Clean Old return_child list = " . $_);
|
||||
delete $self->{return_child}->{$_};
|
||||
}
|
||||
}
|
||||
|
||||
return $progress;
|
||||
}
|
||||
|
||||
sub reqclient {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $result;
|
||||
eval {
|
||||
$result = JSON::XS->new->utf8->decode($options{data});
|
||||
};
|
||||
if ($@) {
|
||||
$self->{logger}->writeLogError("Cannot decode JSON: $@ (options{data}");
|
||||
return ;
|
||||
}
|
||||
|
||||
if ($self->{vsphere_connected}) {
|
||||
$self->{logger}->writeLogInfo("vpshere '" . $self->{whoaim} . "' handler asking: $options{data}");
|
||||
|
||||
$self->{child_proc}->{$result->{identity}} = { ctime => time() };
|
||||
$self->{child_proc}->{$result->{identity}}->{pid} = fork;
|
||||
if (!$self->{child_proc}->{$result->{identity}}->{pid}) {
|
||||
$self->{modules_registry}->{$result->{command}}->set_connector(connector => $self);
|
||||
$self->{modules_registry}->{$result->{command}}->initArgs(arguments => $result);
|
||||
$self->{modules_registry}->{$result->{command}}->run();
|
||||
|
||||
centreon::vmware::common::response(token => 'RESPSERVER2', endpoint => $backend, reinit => 'ipc://' . $self->{config_ipc_file});
|
||||
zmq_close($backend);
|
||||
exit(0);
|
||||
}
|
||||
} else {
|
||||
$self->response_router(
|
||||
code => -1,
|
||||
msg => 'Container connection problem',
|
||||
identity => $result->{identity}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
sub vsphere_event {
|
||||
while (1) {
|
||||
# Process all parts of the message
|
||||
my $msg = zmq_msg_init();
|
||||
my $rv = zmq_msg_recv($msg, $backend, undef);
|
||||
if ($rv == -1) {
|
||||
$connector->{logger}->writeLogError("zmq_recvmsg error: $!");
|
||||
last;
|
||||
}
|
||||
my $data = zmq_msg_data($msg);
|
||||
zmq_msg_close($msg);
|
||||
|
||||
if ($data =~ /^REQCLIENT\s+(.*)$/msi) {
|
||||
$connector->reqclient(data => $1);
|
||||
}
|
||||
|
||||
my $more = zmq_getsockopt($backend, ZMQ_RCVMORE);
|
||||
last unless $more;
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($connector) = shift;
|
||||
my $timeout_process = 0;
|
||||
|
||||
$connector->{logger}->writeLogInfo("'" . $connector->{whoaim} . "' init begin");
|
||||
my $context = zmq_init();
|
||||
|
||||
$backend = zmq_socket($context, ZMQ_DEALER);
|
||||
zmq_setsockopt($backend, ZMQ_IDENTITY, "server-" . $connector->{whoaim});
|
||||
zmq_setsockopt($backend, ZMQ_LINGER, 0); # we discard
|
||||
zmq_connect($backend, 'ipc://' . $connector->{config_ipc_file});
|
||||
centreon::vmware::common::response(token => 'READY', endpoint => $backend, force_response => '');
|
||||
|
||||
# Initialize poll set
|
||||
my @poll = (
|
||||
{
|
||||
socket => $backend,
|
||||
events => ZMQ_POLLIN,
|
||||
callback => \&vsphere_event,
|
||||
},
|
||||
);
|
||||
|
||||
$connector->{logger}->writeLogInfo("'" . $connector->{whoaim} . "' init done");
|
||||
while (1) {
|
||||
my $progress = $connector->verify_child();
|
||||
|
||||
#####
|
||||
# Manage ending
|
||||
#####
|
||||
if ($connector->{stop} && $timeout_process > $connector->{config_stop_child_timeout}) {
|
||||
$connector->{logger}->writeLogError("'" . $connector->{whoaim} . "' Kill child not gently.");
|
||||
foreach (keys %{$connector->{child_proc}}) {
|
||||
kill('INT', $connector->{child_proc}->{$_}->{pid});
|
||||
}
|
||||
$progress = 0;
|
||||
}
|
||||
if ($connector->{stop} && !$progress) {
|
||||
if ($connector->{vsphere_connected}) {
|
||||
eval {
|
||||
$connector->{session}->logout();
|
||||
};
|
||||
}
|
||||
|
||||
zmq_close($backend);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
###
|
||||
# Manage vpshere connection
|
||||
###
|
||||
if ($connector->{vsphere_connected} == 1 &&
|
||||
defined($connector->{last_time_vsphere}) && defined($connector->{last_time_check}) &&
|
||||
$connector->{last_time_vsphere} < $connector->{last_time_check}) {
|
||||
$connector->{logger}->writeLogError("'" . $connector->{whoaim} . "' Disconnect");
|
||||
$connector->{vsphere_connected} = 0;
|
||||
eval {
|
||||
$connector->{session}->logout();
|
||||
};
|
||||
delete $connector->{session};
|
||||
}
|
||||
|
||||
if ($connector->{vsphere_connected} == 0) {
|
||||
if (!centreon::vmware::common::connect_vsphere(
|
||||
logger => $connector->{logger},
|
||||
whoaim => $connector->{whoaim},
|
||||
connect_timeout => $connector->{config_vsphere_connect_timeout},
|
||||
connector => $connector,
|
||||
url => $connector->{config_vsphere_url},
|
||||
username => $connector->{config_vsphere_user},
|
||||
password => $connector->{config_vsphere_pass},
|
||||
vsan_enabled => $connector->{vsan_enabled}
|
||||
)
|
||||
) {
|
||||
$connector->{logger}->writeLogInfo("'" . $connector->{whoaim} . "' Vsphere connection ok");
|
||||
$connector->{logger}->writeLogInfo("'" . $connector->{whoaim} . "' Create perf counters cache in progress");
|
||||
if (!centreon::vmware::common::cache_perf_counters($connector)) {
|
||||
$connector->{last_time_vsphere} = time();
|
||||
$connector->{keeper_session_time} = time();
|
||||
$connector->{vsphere_connected} = 1;
|
||||
$connector->{logger}->writeLogInfo("'" . $connector->{whoaim} . "' Create perf counters cache done");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
###
|
||||
# Manage session time
|
||||
###
|
||||
if ($connector->{vsphere_connected} == 1 &&
|
||||
defined($connector->{keeper_session_time}) &&
|
||||
(time() - $connector->{keeper_session_time}) > ($connector->{config_vsphere_session_heartbeat} * 60)) {
|
||||
centreon::vmware::common::heartbeat(connector => $connector);
|
||||
}
|
||||
|
||||
my $data_element;
|
||||
my @rh_set;
|
||||
if ($connector->{vsphere_connected} == 0) {
|
||||
sleep(5);
|
||||
}
|
||||
if ($connector->{stop} != 0) {
|
||||
sleep(1);
|
||||
$timeout_process++;
|
||||
next;
|
||||
}
|
||||
|
||||
zmq_poll(\@poll, 5000);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
|
@ -0,0 +1,471 @@
|
|||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package centreon::vmware::http::backend::curl;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use URI;
|
||||
use Net::Curl::Easy;
|
||||
use centreon::vmware::http::backend::curlconstants;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = {};
|
||||
bless $self, $class;
|
||||
|
||||
$self->{logger} = $options{logger};
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{constant_cb} = \¢reon::vmware::http::backend::curlconstants::get_constant_value;
|
||||
|
||||
if (!defined($options{request}->{curl_opt})) {
|
||||
$options{request}->{curl_opt} = [];
|
||||
}
|
||||
}
|
||||
|
||||
my $http_code_explained = {
|
||||
100 => 'Continue',
|
||||
101 => 'Switching Protocols',
|
||||
200 => 'OK',
|
||||
201 => 'Created',
|
||||
202 => 'Accepted',
|
||||
203 => 'Non-Authoritative Information',
|
||||
204 => 'No Content',
|
||||
205 => 'Reset Content',
|
||||
206 => 'Partial Content',
|
||||
300 => 'Multiple Choices',
|
||||
301 => 'Moved Permanently',
|
||||
302 => 'Found',
|
||||
303 => 'See Other',
|
||||
304 => 'Not Modified',
|
||||
305 => 'Use Proxy',
|
||||
306 => '(Unused)',
|
||||
307 => 'Temporary Redirect',
|
||||
400 => 'Bad Request',
|
||||
401 => 'Unauthorized',
|
||||
402 => 'Payment Required',
|
||||
403 => 'Forbidden',
|
||||
404 => 'Not Found',
|
||||
405 => 'Method Not Allowed',
|
||||
406 => 'Not Acceptable',
|
||||
407 => 'Proxy Authentication Required',
|
||||
408 => 'Request Timeout',
|
||||
409 => 'Conflict',
|
||||
410 => 'Gone',
|
||||
411 => 'Length Required',
|
||||
412 => 'Precondition Failed',
|
||||
413 => 'Request Entity Too Large',
|
||||
414 => 'Request-URI Too Long',
|
||||
415 => 'Unsupported Media Type',
|
||||
416 => 'Requested Range Not Satisfiable',
|
||||
417 => 'Expectation Failed',
|
||||
450 => 'Timeout reached', # custom code
|
||||
451 => 'Failed Connection Host', # custom code
|
||||
500 => 'Internal Server Error',
|
||||
501 => 'Not Implemented',
|
||||
502 => 'Bad Gateway',
|
||||
503 => 'Service Unavailable',
|
||||
504 => 'Gateway Timeout',
|
||||
505 => 'HTTP Version Not Supported'
|
||||
};
|
||||
|
||||
sub cb_debug {
|
||||
my ($easy, $type, $data, $uservar) = @_;
|
||||
|
||||
chomp $data;
|
||||
$data =~ s/\r//mg;
|
||||
|
||||
my $msg = '';
|
||||
if ($type == $uservar->{constant_cb}->(name => 'CURLINFO_TEXT')) {
|
||||
$msg = sprintf("== Info: %s", $data);
|
||||
}
|
||||
if ($type == $uservar->{constant_cb}->(name => 'CURLINFO_HEADER_OUT')) {
|
||||
$msg = sprintf("=> Send header: %s", $data);
|
||||
}
|
||||
if ($type == $uservar->{constant_cb}->(name => 'CURLINFO_DATA_OUT')) {
|
||||
$msg = sprintf("=> Send data: %s", $data);
|
||||
}
|
||||
if ($type == $uservar->{constant_cb}->(name => 'CURLINFO_SSL_DATA_OUT')) {
|
||||
#$msg = sprintf("=> Send SSL data: %s", $data);
|
||||
return 0;
|
||||
}
|
||||
if ($type == $uservar->{constant_cb}->(name => 'CURLINFO_HEADER_IN')) {
|
||||
$msg = sprintf("=> Recv header: %s", $data);
|
||||
}
|
||||
if ($type == $uservar->{constant_cb}->(name => 'CURLINFO_DATA_IN')) {
|
||||
$msg = sprintf("=> Recv data: %s", $data);
|
||||
}
|
||||
if ($type == $uservar->{constant_cb}->(name => 'CURLINFO_SSL_DATA_IN')) {
|
||||
#$msg = sprintf("=> Recv SSL data: %s", $data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
$uservar->{logger}->writeLogDebug($msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub curl_setopt {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
eval {
|
||||
$self->{curl_easy}->setopt($options{option}, $options{parameter});
|
||||
};
|
||||
if ($@) {
|
||||
$self->{logger}->writeLogError("curl setopt error: '" . $@ . "'.");
|
||||
}
|
||||
}
|
||||
|
||||
sub set_method {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_CUSTOMREQUEST'), parameter => undef);
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_POSTFIELDS'), parameter => undef);
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_HTTPGET'), parameter => 1);
|
||||
|
||||
if ($options{request}->{method} eq 'GET') {
|
||||
return ;
|
||||
}
|
||||
|
||||
if ($options{content_type_forced} == 1) {
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_POSTFIELDS'), parameter => $options{request}->{query_form_post})
|
||||
if (defined($options{request}->{query_form_post}));
|
||||
} elsif (defined($options{request}->{post_params})) {
|
||||
my $uri_post = URI->new();
|
||||
$uri_post->query_form($options{request}->{post_params});
|
||||
push @{$options{headers}}, 'Content-Type: application/x-www-form-urlencoded';
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_POSTFIELDS'), parameter => $uri_post->query);
|
||||
}
|
||||
|
||||
if ($options{request}->{method} eq 'POST') {
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_POST'), parameter => 1);
|
||||
}
|
||||
if ($options{request}->{method} eq 'PUT') {
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_CUSTOMREQUEST'), parameter => $options{request}->{method});
|
||||
}
|
||||
if ($options{request}->{method} eq 'DELETE') {
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_CUSTOMREQUEST'), parameter => $options{request}->{method});
|
||||
}
|
||||
}
|
||||
|
||||
sub set_auth {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{request}->{credentials})) {
|
||||
if (defined($options{request}->{basic})) {
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_HTTPAUTH'), parameter => $self->{constant_cb}->(name => 'CURLAUTH_BASIC'));
|
||||
} elsif (defined($options{request}->{ntlmv2})) {
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_HTTPAUTH'), parameter => $self->{constant_cb}->(name => 'CURLAUTH_NTLM'));
|
||||
} else {
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_HTTPAUTH'), parameter => $self->{constant_cb}->(name => 'CURLAUTH_ANY'));
|
||||
}
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_USERPWD'), parameter => $options{request}->{username} . ':' . $options{request}->{password});
|
||||
}
|
||||
|
||||
if (defined($options{request}->{cert_file}) && $options{request}->{cert_file} ne '') {
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_SSLCERT'), parameter => $options{request}->{cert_file});
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_SSLKEY'), parameter => $options{request}->{key_file});
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_KEYPASSWD'), parameter => $options{request}->{cert_pwd});
|
||||
}
|
||||
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_SSLCERTTYPE'), parameter => "PEM");
|
||||
if (defined($options{request}->{cert_pkcs12})) {
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_SSLCERTTYPE'), parameter => "P12");
|
||||
}
|
||||
}
|
||||
|
||||
sub set_proxy {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{request}->{proxyurl}) && $options{request}->{proxyurl} ne '') {
|
||||
if ($options{request}->{proxyurl} =~ /^(?:http|https):\/\/(.*?):(.*?)@/) {
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_PROXYUSERNAME'), parameter => $1);
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_PROXYPASSWORD'), parameter => $2);
|
||||
$options{request}->{proxyurl} =~ s/\/\/$1:$2@//;
|
||||
}
|
||||
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_PROXY'), parameter => $options{request}->{proxyurl});
|
||||
}
|
||||
|
||||
if (defined($options{request}->{proxypac}) && $options{request}->{proxypac} ne '') {
|
||||
$self->{logger}->writeLogError('Unsupported proxypac option');
|
||||
}
|
||||
}
|
||||
|
||||
sub trim {
|
||||
my ($self, $value) = @_;
|
||||
|
||||
# Sometimes there is a null character
|
||||
$value =~ s/\x00$//;
|
||||
$value =~ s/^[ \t\n]+//;
|
||||
$value =~ s/[ \t\n]+$//;
|
||||
return $value;
|
||||
}
|
||||
|
||||
sub set_extra_curl_opt {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $entries = {};
|
||||
foreach (@{$options{request}->{curl_opt}}) {
|
||||
my ($key, $value) = split /=>/;
|
||||
$key = $self->trim($key);
|
||||
|
||||
if (!defined($entries->{$key})) {
|
||||
$entries->{$key} = { val => [], force_array => 0 };
|
||||
}
|
||||
|
||||
$value = $self->trim($value);
|
||||
if ($value =~ /^\[(.*)\]$/) {
|
||||
$entries->{$key}->{force_array} = 1;
|
||||
$value = $self->trim($1);
|
||||
}
|
||||
if ($value =~ /^CURLOPT|CURL/) {
|
||||
$value = $self->{constant_cb}->(name => $value);
|
||||
}
|
||||
|
||||
push @{$entries->{$key}->{val}}, $value;
|
||||
}
|
||||
|
||||
foreach (keys %$entries) {
|
||||
my $key = $_;
|
||||
if (/^CURLOPT|CURL/) {
|
||||
$key = $self->{constant_cb}->(name => $_);
|
||||
}
|
||||
|
||||
if ($entries->{$_}->{force_array} == 1 || scalar(@{$entries->{$_}->{val}}) > 1) {
|
||||
$self->curl_setopt(option => $key, parameter => $entries->{$_}->{val});
|
||||
} else {
|
||||
$self->curl_setopt(option => $key, parameter => pop @{$entries->{$_}->{val}});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sub cb_get_header {
|
||||
my ($easy, $header, $uservar) = @_;
|
||||
|
||||
$header =~ s/[\r\n]//g;
|
||||
if ($header =~ /^[\r\n]*$/) {
|
||||
$uservar->{nheaders}++;
|
||||
} else {
|
||||
$uservar->{response_headers}->[$uservar->{nheaders}] = {}
|
||||
if (!defined($uservar->{response_headers}->[$uservar->{nheaders}]));
|
||||
if ($header =~ /^(\S(?:.*?))\s*:\s*(.*)/) {
|
||||
my $header_name = lc($1);
|
||||
$uservar->{response_headers}->[$uservar->{nheaders}]->{$header_name} = []
|
||||
if (!defined($uservar->{response_headers}->[$uservar->{nheaders}]->{$header_name}));
|
||||
push @{$uservar->{response_headers}->[$uservar->{nheaders}]->{$header_name}}, $2;
|
||||
} else {
|
||||
$uservar->{response_headers}->[$uservar->{nheaders}]->{response_line} = $header;
|
||||
}
|
||||
}
|
||||
|
||||
return length($_[1]);
|
||||
}
|
||||
|
||||
sub request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (!defined($self->{curl_easy})) {
|
||||
$self->{curl_easy} = Net::Curl::Easy->new();
|
||||
}
|
||||
|
||||
if ($self->{logger}->is_debug()) {
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_DEBUGFUNCTION'), parameter => \&cb_debug);
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_DEBUGDATA'), parameter => $self);
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_VERBOSE'), parameter => 1);
|
||||
}
|
||||
|
||||
if (defined($options{request}->{timeout})) {
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_TIMEOUT'), parameter => $options{request}->{timeout});
|
||||
}
|
||||
if (defined($options{request}->{cookies_file})) {
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_COOKIEFILE'), parameter => $options{request}->{cookies_file});
|
||||
}
|
||||
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_FOLLOWLOCATION'), parameter => 1);
|
||||
if (defined($options{request}->{no_follow})) {
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_FOLLOWLOCATION'), parameter => 0);
|
||||
}
|
||||
|
||||
my $url;
|
||||
if (defined($options{request}->{full_url})) {
|
||||
$url = $options{request}->{full_url};
|
||||
} elsif (defined($options{request}->{port}) && $options{request}->{port} =~ /^[0-9]+$/) {
|
||||
$url = $options{request}->{proto}. "://" . $options{request}->{hostname} . ':' . $options{request}->{port} . $options{request}->{url_path};
|
||||
} else {
|
||||
$url = $options{request}->{proto}. "://" . $options{request}->{hostname} . $options{request}->{url_path};
|
||||
}
|
||||
|
||||
if (defined($options{request}->{http_peer_addr}) && $options{request}->{http_peer_addr} ne '') {
|
||||
$url =~ /^(?:http|https):\/\/(.*?)(\/|\:|$)/;
|
||||
$self->{curl_easy}->setopt(
|
||||
$self->{constant_cb}->(name => 'CURLOPT_RESOLVE'),
|
||||
[$1 . ':' . $options{request}->{port_force} . ':' . $options{request}->{http_peer_addr}]
|
||||
);
|
||||
}
|
||||
|
||||
my $uri = URI->new($url);
|
||||
if (defined($options{request}->{get_params})) {
|
||||
$uri->query_form($options{request}->{get_params});
|
||||
}
|
||||
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_URL'), parameter => $uri);
|
||||
|
||||
my $headers = [];
|
||||
my $content_type_forced = 0;
|
||||
foreach my $key (keys %{$options{request}->{headers}}) {
|
||||
push @$headers, $key . ':' . $options{request}->{headers}->{$key};
|
||||
if ($key =~ /content-type/i) {
|
||||
$content_type_forced = 1;
|
||||
}
|
||||
}
|
||||
|
||||
$self->set_method(%options, content_type_forced => $content_type_forced, headers => $headers);
|
||||
|
||||
if (scalar(@$headers) > 0) {
|
||||
$self->{curl_easy}->setopt($self->{constant_cb}->(name => 'CURLOPT_HTTPHEADER'), $headers);
|
||||
}
|
||||
|
||||
if (defined($options{request}->{cacert_file}) && $options{request}->{cacert_file} ne '') {
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_CAINFO'), parameter => $options{request}->{cacert_file});
|
||||
}
|
||||
|
||||
$self->set_auth(%options);
|
||||
$self->set_proxy(%options);
|
||||
$self->set_extra_curl_opt(%options);
|
||||
|
||||
$self->{response_body} = '';
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_FILE'), parameter => \$self->{response_body});
|
||||
$self->{nheaders} = 0;
|
||||
$self->{response_headers} = [{}];
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_HEADERDATA'), parameter => $self);
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_HEADERFUNCTION'), parameter => \&cb_get_header);
|
||||
|
||||
eval {
|
||||
$SIG{__DIE__} = sub {};
|
||||
|
||||
$self->{curl_easy}->perform();
|
||||
};
|
||||
if ($@) {
|
||||
my $err = $@;
|
||||
if (ref($@) eq "Net::Curl::Easy::Code") {
|
||||
my $num = $@;
|
||||
if ($num == $self->{constant_cb}->(name => 'CURLE_OPERATION_TIMEDOUT')) {
|
||||
$self->{response_code} = 450;
|
||||
} elsif ($num == $self->{constant_cb}->(name => 'CURLE_COULDNT_CONNECT')) {
|
||||
$self->{response_code} = 451;
|
||||
}
|
||||
}
|
||||
|
||||
if (!defined($self->{response_code})) {
|
||||
$self->{logger}->writeLogError('curl perform error : ' . $err);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$self->{response_code} = $self->{curl_easy}->getinfo($self->{constant_cb}->(name => 'CURLINFO_RESPONSE_CODE'));
|
||||
|
||||
return (0, $self->{response_body});
|
||||
}
|
||||
|
||||
sub get_headers {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $headers = '';
|
||||
foreach (keys %{$self->{response_headers}->[$options{nheader}]}) {
|
||||
next if (/response_line/);
|
||||
foreach my $value (@{$self->{response_headers}->[$options{nheader}]->{$_}}) {
|
||||
$headers .= "$_: " . $value . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
|
||||
sub get_first_header {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (!defined($options{name})) {
|
||||
return $self->get_headers(nheader => 0);
|
||||
}
|
||||
|
||||
return undef
|
||||
if (!defined($self->{response_headers}->[0]->{ lc($options{name}) }));
|
||||
return wantarray ? @{$self->{response_headers}->[0]->{ lc($options{name}) }} : $self->{response_headers}->[0]->{ lc($options{name}) }->[0];
|
||||
}
|
||||
|
||||
sub get_header {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (!defined($options{name})) {
|
||||
return $self->get_headers(nheader => -1);
|
||||
}
|
||||
|
||||
return undef
|
||||
if (!defined($self->{response_headers}->[-1]->{ lc($options{name}) }));
|
||||
return wantarray ? @{$self->{response_headers}->[-1]->{ lc($options{name}) }} : $self->{response_headers}->[-1]->{ lc($options{name}) }->[0];
|
||||
}
|
||||
|
||||
sub get_code {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return $self->{response_code};
|
||||
}
|
||||
|
||||
sub get_message {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return $http_code_explained->{$self->{response_code}};
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
HTTP Curl backend layer.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
HTTP Curl backend layer.
|
||||
|
||||
=head1 BACKEND CURL OPTIONS
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--curl-opt>
|
||||
|
||||
Set CURL Options (--curl-opt="CURLOPT_SSL_VERIFYPEER => 0" --curl-opt="CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1_1" ).
|
||||
|
||||
=back
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
B<http>.
|
||||
|
||||
=cut
|
|
@ -0,0 +1,33 @@
|
|||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package centreon::vmware::http::backend::curlconstants;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Net::Curl::Easy qw(:constants);
|
||||
|
||||
sub get_constant_value {
|
||||
my (%options) = @_;
|
||||
|
||||
return eval $options{name};
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,251 @@
|
|||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package centreon::vmware::http::backend::lwp;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::vmware::http::backend::useragent;
|
||||
use URI;
|
||||
use IO::Socket::SSL;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = {};
|
||||
bless $self, $class;
|
||||
|
||||
$self->{logger} = $options{logger};
|
||||
$self->{ua} = undef;
|
||||
$self->{debug_handlers} = 0;
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{ssl_context} = '';
|
||||
if (!defined($options{request}->{ssl_opt})) {
|
||||
$options{request}->{ssl_opt} = [];
|
||||
}
|
||||
if (defined($options{request}->{ssl}) && $options{request}->{ssl} ne '') {
|
||||
push @{$options{request}->{ssl_opt}}, 'SSL_version => ' . $options{request}->{ssl};
|
||||
}
|
||||
if (defined($options{request}->{cert_file}) && !defined($options{request}->{cert_pkcs12})) {
|
||||
push @{$options{request}->{ssl_opt}}, 'SSL_use_cert => 1';
|
||||
push @{$options{request}->{ssl_opt}}, 'SSL_cert_file => "' . $options{request}->{cert_file} . '"';
|
||||
push @{$options{request}->{ssl_opt}}, 'SSL_key_file => "' . $options{request}->{key_file} . '"'
|
||||
if (defined($options{request}->{key_file}));
|
||||
push @{$options{request}->{ssl_opt}}, 'SSL_ca_file => "' . $options{request}->{cacert_file} . '"'
|
||||
if (defined($options{request}->{cacert_file}));
|
||||
}
|
||||
my $append = '';
|
||||
foreach (@{$options{request}->{ssl_opt}}) {
|
||||
if ($_ ne '') {
|
||||
$self->{ssl_context} .= $append . $_;
|
||||
$append = ', ';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub set_proxy {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{request}->{proxyurl}) && $options{request}->{proxyurl} ne '') {
|
||||
$self->{ua}->proxy(['http', 'https'], $options{request}->{proxyurl});
|
||||
}
|
||||
}
|
||||
|
||||
sub request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $request_options = $options{request};
|
||||
if (!defined($self->{ua})) {
|
||||
$self->{ua} = centreon::plugins::backend::http::useragent->new(
|
||||
keep_alive => 1, protocols_allowed => ['http', 'https'], timeout => $request_options->{timeout},
|
||||
credentials => $request_options->{credentials}, username => $request_options->{username}, password => $request_options->{password});
|
||||
}
|
||||
|
||||
if ($self->{logger}->is_debug() && $self->{debug_handlers} == 0) {
|
||||
$self->{debug_handlers} = 1;
|
||||
$self->{ua}->add_handler("request_send", sub {
|
||||
my ($response, $ua, $handler) = @_;
|
||||
|
||||
$self->{logger}->writeLogDebug("======> request send");
|
||||
$self->{logger}->writeLogDebug($response->as_string);
|
||||
return ;
|
||||
});
|
||||
$self->{ua}->add_handler("response_done", sub {
|
||||
my ($response, $ua, $handler) = @_;
|
||||
|
||||
$self->{logger}->writeLogDebug("======> response done");
|
||||
$self->{logger}->writeLogDebug($response->as_string);
|
||||
return ;
|
||||
});
|
||||
}
|
||||
|
||||
if (defined($request_options->{no_follow})) {
|
||||
$self->{ua}->requests_redirectable(undef);
|
||||
} else {
|
||||
$self->{ua}->requests_redirectable([ 'GET', 'HEAD', 'POST' ]);
|
||||
}
|
||||
if (defined($request_options->{http_peer_addr})) {
|
||||
push @LWP::Protocol::http::EXTRA_SOCK_OPTS, PeerAddr => $request_options->{http_peer_addr};
|
||||
}
|
||||
|
||||
my ($req, $url);
|
||||
if (defined($request_options->{full_url})) {
|
||||
$url = $request_options->{full_url};
|
||||
} elsif (defined($request_options->{port}) && $request_options->{port} =~ /^[0-9]+$/) {
|
||||
$url = $request_options->{proto}. "://" . $request_options->{hostname} . ':' . $request_options->{port} . $request_options->{url_path};
|
||||
} else {
|
||||
$url = $request_options->{proto}. "://" . $request_options->{hostname} . $request_options->{url_path};
|
||||
}
|
||||
|
||||
my $uri = URI->new($url);
|
||||
if (defined($request_options->{get_params})) {
|
||||
$uri->query_form($request_options->{get_params});
|
||||
}
|
||||
$req = HTTP::Request->new($request_options->{method}, $uri);
|
||||
|
||||
my $content_type_forced;
|
||||
foreach my $key (keys %{$request_options->{headers}}) {
|
||||
if ($key !~ /content-type/i) {
|
||||
$req->header($key => $request_options->{headers}->{$key});
|
||||
} else {
|
||||
$content_type_forced = $request_options->{headers}->{$key};
|
||||
}
|
||||
}
|
||||
|
||||
if ($request_options->{method} eq 'POST') {
|
||||
if (defined($content_type_forced)) {
|
||||
$req->content_type($content_type_forced);
|
||||
$req->content($request_options->{query_form_post});
|
||||
} else {
|
||||
my $uri_post = URI->new();
|
||||
if (defined($request_options->{post_params})) {
|
||||
$uri_post->query_form($request_options->{post_params});
|
||||
}
|
||||
$req->content_type('application/x-www-form-urlencoded');
|
||||
$req->content($uri_post->query);
|
||||
}
|
||||
}
|
||||
|
||||
if (defined($request_options->{credentials}) && defined($request_options->{basic})) {
|
||||
$req->authorization_basic($request_options->{username}, $request_options->{password});
|
||||
}
|
||||
|
||||
$self->set_proxy(request => $request_options, url => $url);
|
||||
|
||||
if (defined($request_options->{cert_pkcs12}) && $request_options->{cert_file} ne '' && $request_options->{cert_pwd} ne '') {
|
||||
eval "use Net::SSL"; die $@ if $@;
|
||||
$ENV{HTTPS_PKCS12_FILE} = $request_options->{cert_file};
|
||||
$ENV{HTTPS_PKCS12_PASSWORD} = $request_options->{cert_pwd};
|
||||
}
|
||||
|
||||
if (defined($self->{ssl_context}) && $self->{ssl_context} ne '') {
|
||||
my $context = new IO::Socket::SSL::SSL_Context(eval $self->{ssl_context});
|
||||
IO::Socket::SSL::set_default_context($context);
|
||||
}
|
||||
|
||||
$self->{response} = $self->{ua}->request($req);
|
||||
|
||||
$self->{headers} = $self->{response}->headers();
|
||||
return (0, $self->{response}->content);
|
||||
}
|
||||
|
||||
sub get_headers {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $headers = '';
|
||||
foreach ($options{response}->header_field_names()) {
|
||||
$headers .= "$_: " . $options{response}->header($_) . "\n";
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
|
||||
sub get_first_header {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my @redirects = $self->{response}->redirects();
|
||||
if (!defined($options{name})) {
|
||||
return $self->get_headers(response => defined($redirects[0]) ? $redirects[0] : $self->{response});
|
||||
}
|
||||
|
||||
return
|
||||
defined($redirects[0]) ?
|
||||
$redirects[0]->headers()->header($options{name}) :
|
||||
$self->{headers}->header($options{name})
|
||||
;
|
||||
}
|
||||
|
||||
sub get_header {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (!defined($options{name})) {
|
||||
return $self->get_headers(response => $self->{response});
|
||||
}
|
||||
return $self->{headers}->header($options{name});
|
||||
}
|
||||
|
||||
sub get_code {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return $self->{response}->code();
|
||||
}
|
||||
|
||||
sub get_message {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return $self->{response}->message();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
HTTP LWP backend layer.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
HTTP LWP backend layer.
|
||||
|
||||
=head1 BACKEND LWP OPTIONS
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--ssl>
|
||||
|
||||
Set SSL version (--ssl=TLSv1).
|
||||
|
||||
=back
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
B<http>.
|
||||
|
||||
=cut
|
|
@ -0,0 +1,50 @@
|
|||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package centreon::vmware::http::backend::useragent;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use base 'LWP::UserAgent';
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = {};
|
||||
bless $self, $class;
|
||||
|
||||
$self = LWP::UserAgent::new(@_);
|
||||
$self->agent('centreon::vmware::http::backend::useragent');
|
||||
|
||||
$self->{credentials} = $options{credentials} if defined($options{credentials});
|
||||
$self->{username} = $options{username} if defined($options{username});
|
||||
$self->{password} = $options{password} if defined($options{password});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub get_basic_credentials {
|
||||
my($self, $realm, $uri, $proxy) = @_;
|
||||
return if $proxy;
|
||||
return $self->{username}, $self->{password} if $self->{credentials} and wantarray;
|
||||
return $self->{username}.":".$self->{password} if $self->{credentials};
|
||||
return undef;
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,257 @@
|
|||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package centreon::vmware::http::http;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = {};
|
||||
bless $self, $class;
|
||||
|
||||
$self->{logger} = $options{logger};
|
||||
$self->{options} = {
|
||||
proto => 'http',
|
||||
url_path => '/',
|
||||
timeout => 5,
|
||||
method => 'GET',
|
||||
};
|
||||
|
||||
$self->{add_headers} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub set_options {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{options} = { %{$self->{options}} };
|
||||
foreach (keys %options) {
|
||||
$self->{options}->{$_} = $options{$_} if (defined($options{$_}));
|
||||
}
|
||||
}
|
||||
|
||||
sub add_header {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{add_headers}->{$options{key}} = $options{value};
|
||||
}
|
||||
|
||||
sub mymodule_load {
|
||||
my ($self, %options) = @_;
|
||||
my $file;
|
||||
($file = ($options{module} =~ /\.pm$/ ? $options{module} : $options{module} . '.pm')) =~ s{::}{/}g;
|
||||
|
||||
eval {
|
||||
local $SIG{__DIE__} = 'IGNORE';
|
||||
require $file;
|
||||
$file =~ s{/}{::}g;
|
||||
$file =~ s/\.pm$//;
|
||||
};
|
||||
if ($@) {
|
||||
$self->{logger}->writeLogError('[core] ' . $options{error_msg} . ' - ' . $@);
|
||||
return 1;
|
||||
}
|
||||
return wantarray ? (0, $file) : 0;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$options{request}->{http_backend} = 'curl'
|
||||
if (!defined($options{request}->{http_backend}) || $options{request}->{http_backend} eq '');
|
||||
$self->{http_backend} = $options{request}->{http_backend};
|
||||
if ($self->{http_backend} !~ /^\s*lwp|curl\s*$/i) {
|
||||
$self->{logger}->writeLogError("Unsupported http backend specified '" . $self->{http_backend} . "'.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!defined($self->{backend_lwp}) && !defined($self->{backend_curl})) {
|
||||
if ($options{request}->{http_backend} eq 'lwp' && $self->mymodule_load(
|
||||
logger => $options{logger}, module => 'centreon::vmware::http::backend::lwp',
|
||||
error_msg => "Cannot load module 'centreon::vmware::http::backend::lwp'."
|
||||
) == 0) {
|
||||
$self->{backend_lwp} = centreon::vmware::http::backend::lwp->new(%options, logger => $self->{logger});
|
||||
}
|
||||
|
||||
if ($options{request}->{http_backend} eq 'curl' && $self->mymodule_load(
|
||||
logger => $options{logger}, module => 'centreon::vmware::http::backend::curl',
|
||||
error_msg => "Cannot load module 'centreon::vmware::http::backend::curl'."
|
||||
) == 0) {
|
||||
$self->{backend_curl} = centreon::vmware::http::backend::curl->new(%options, logger => $self->{logger});
|
||||
}
|
||||
}
|
||||
|
||||
if (($options{request}->{proto} ne 'http') && ($options{request}->{proto} ne 'https')) {
|
||||
$self->{logger}->writeLogError("Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
|
||||
return 1;
|
||||
}
|
||||
if (!defined($options{request}->{hostname})) {
|
||||
$self->{logger}->writeLogError("Please set the hostname option");
|
||||
return 1;
|
||||
}
|
||||
if ((defined($options{request}->{credentials})) && (!defined($options{request}->{username}) || !defined($options{request}->{password}))) {
|
||||
$self->{logger}->writeLogError("You need to set --username= and --password= options when --credentials is used");
|
||||
return 1;
|
||||
}
|
||||
if ((defined($options{request}->{cert_pkcs12})) && (!defined($options{request}->{cert_file}) && !defined($options{request}->{cert_pwd}))) {
|
||||
$self->{logger}->writeLogError("You need to set --cert-file= and --cert-pwd= options when --pkcs12 is used");
|
||||
return 1;
|
||||
}
|
||||
|
||||
$options{request}->{port_force} = $self->get_port();
|
||||
|
||||
$options{request}->{headers} = {};
|
||||
if (defined($options{request}->{header})) {
|
||||
foreach (@{$options{request}->{header}}) {
|
||||
if (/^(.*?):(.*)/) {
|
||||
$options{request}->{headers}->{$1} = $2;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (keys %{$self->{add_headers}}) {
|
||||
$options{request}->{headers}->{$_} = $self->{add_headers}->{$_};
|
||||
}
|
||||
|
||||
foreach my $method (('get', 'post')) {
|
||||
if (defined($options{request}->{$method . '_param'})) {
|
||||
$options{request}->{$method . '_params'} = {};
|
||||
foreach (@{$options{request}->{$method . '_param'}}) {
|
||||
if (/^([^=]+)={0,1}(.*)$/) {
|
||||
my $key = $1;
|
||||
my $value = defined($2) ? $2 : 1;
|
||||
if (defined($options{request}->{$method . '_params'}->{$key})) {
|
||||
if (ref($options{request}->{$method . '_params'}->{$key}) ne 'ARRAY') {
|
||||
$options{request}->{$method . '_params'}->{$key} = [ $options{request}->{$method . '_params'}->{$key} ];
|
||||
}
|
||||
push @{$options{request}->{$method . '_params'}->{$key}}, $value;
|
||||
} else {
|
||||
$options{request}->{$method . '_params'}->{$key} = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$self->{ 'backend_' . $self->{http_backend} }->check_options(%options);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub get_port {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $port = '';
|
||||
if (defined($self->{options}->{port}) && $self->{options}->{port} ne '') {
|
||||
$port = $self->{options}->{port};
|
||||
} else {
|
||||
$port = 80 if ($self->{options}->{proto} eq 'http');
|
||||
$port = 443 if ($self->{options}->{proto} eq 'https');
|
||||
}
|
||||
|
||||
return $port;
|
||||
}
|
||||
|
||||
sub get_port_request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $port = '';
|
||||
if (defined($self->{options}->{port}) && $self->{options}->{port} ne '') {
|
||||
$port = $self->{options}->{port};
|
||||
}
|
||||
return $port;
|
||||
}
|
||||
|
||||
sub request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $request_options = { %{$self->{options}} };
|
||||
foreach (keys %options) {
|
||||
$request_options->{$_} = $options{$_} if (defined($options{$_}));
|
||||
}
|
||||
return 1 if ($self->check_options(request => $request_options));
|
||||
|
||||
return $self->{'backend_' . $self->{http_backend}}->request(request => $request_options);
|
||||
}
|
||||
|
||||
sub get_first_header {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return $self->{'backend_' . $self->{http_backend}}->get_first_header(%options);
|
||||
}
|
||||
|
||||
sub get_header {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return $self->{'backend_' . $self->{http_backend}}->get_header(%options);
|
||||
}
|
||||
|
||||
sub get_code {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return $self->{'backend_' . $self->{http_backend}}->get_code();
|
||||
}
|
||||
|
||||
sub get_message {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return $self->{'backend_' . $self->{http_backend}}->get_message();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
HTTP abstraction layer.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
HTTP abstraction layer for lwp and curl backends
|
||||
|
||||
=head1 HTTP GLOBAL OPTIONS
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--http-peer-addr>
|
||||
|
||||
Set the address you want to connect (Useful if hostname is only a vhost. no ip resolve)
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL
|
||||
|
||||
=item B<--proxypac>
|
||||
|
||||
Proxy pac file (can be an url or local file)
|
||||
|
||||
=item B<--http-backend>
|
||||
|
||||
Set the backend used (Default: 'lwp')
|
||||
For curl: --http-backend=curl
|
||||
|
||||
=back
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
B<http>.
|
||||
|
||||
=cut
|
|
@ -0,0 +1,218 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::logger;
|
||||
|
||||
=head1 NOM
|
||||
|
||||
centreon::vmware::logger - Simple logging module
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use centreon::polling;
|
||||
|
||||
my $logger = new centreon::vmware::logger();
|
||||
|
||||
$logger->writeLogInfo("information");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module offers a simple interface to write log messages to various output:
|
||||
|
||||
* standard output
|
||||
* file
|
||||
* syslog
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Sys::Syslog qw(:standard :macros);
|
||||
use IO::Handle;
|
||||
|
||||
my %severities = (1 => LOG_INFO,
|
||||
2 => LOG_ERR,
|
||||
4 => LOG_DEBUG);
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
|
||||
my $self = bless
|
||||
{
|
||||
file => 0,
|
||||
filehandler => undef,
|
||||
# 0 = nothing, 1 = critical, 3 = info, 7 = debug
|
||||
severity => 3,
|
||||
old_severity => 3,
|
||||
# 0 = stdout, 1 = file, 2 = syslog
|
||||
log_mode => 0,
|
||||
# Output pid of current process
|
||||
withpid => 0,
|
||||
# syslog
|
||||
log_facility => undef,
|
||||
log_option => LOG_PID,
|
||||
}, $class;
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub file_mode($$) {
|
||||
my ($self, $file) = @_;
|
||||
|
||||
if (defined($self->{filehandler})) {
|
||||
$self->{filehandler}->close();
|
||||
}
|
||||
if (open($self->{filehandler}, ">>", $file)){
|
||||
$self->{log_mode} = 1;
|
||||
$self->{filehandler}->autoflush(1);
|
||||
$self->{file_name} = $file;
|
||||
return 1;
|
||||
}
|
||||
$self->{filehandler} = undef;
|
||||
print STDERR "Cannot open file $file: $!\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub is_file_mode {
|
||||
my $self = shift;
|
||||
|
||||
if ($self->{log_mode} == 1) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub is_debug {
|
||||
my $self = shift;
|
||||
|
||||
if (($self->{severity} & 4) == 0) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub syslog_mode($$$) {
|
||||
my ($self, $logopt, $facility) = @_;
|
||||
|
||||
$self->{log_mode} = 2;
|
||||
openlog($0, $logopt, $facility);
|
||||
return 1;
|
||||
}
|
||||
|
||||
# For daemons
|
||||
sub redirect_output {
|
||||
my $self = shift;
|
||||
|
||||
if ($self->is_file_mode()) {
|
||||
open my $lfh, '>>', $self->{file_name};
|
||||
open STDOUT, '>&', $lfh;
|
||||
open STDERR, '>&', $lfh;
|
||||
}
|
||||
}
|
||||
|
||||
sub set_default_severity {
|
||||
my $self = shift;
|
||||
|
||||
$self->{severity} = $self->{old_severity};
|
||||
}
|
||||
|
||||
# Getter/Setter Log severity
|
||||
sub severity {
|
||||
my $self = shift;
|
||||
if (@_) {
|
||||
my $save_severity = $self->{severity};
|
||||
if ($_[0] =~ /^[012347]$/) {
|
||||
$self->{severity} = $_[0];
|
||||
} elsif ($_[0] eq "none") {
|
||||
$self->{severity} = 0;
|
||||
} elsif ($_[0] eq "error") {
|
||||
$self->{severity} = 1;
|
||||
} elsif ($_[0] eq "info") {
|
||||
$self->{severity} = 3;
|
||||
} elsif ($_[0] eq "debug") {
|
||||
$self->{severity} = 7;
|
||||
} else {
|
||||
$self->writeLogError("Wrong severity value set.");
|
||||
return -1;
|
||||
}
|
||||
$self->{old_severity} = $save_severity;
|
||||
}
|
||||
return $self->{severity};
|
||||
}
|
||||
|
||||
sub withpid {
|
||||
my $self = shift;
|
||||
if (@_) {
|
||||
$self->{withpid} = $_[0];
|
||||
}
|
||||
return $self->{withpid};
|
||||
}
|
||||
|
||||
sub get_date {
|
||||
my $self = shift;
|
||||
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time());
|
||||
return sprintf("%04d-%02d-%02d %02d:%02d:%02d",
|
||||
$year+1900, $mon+1, $mday, $hour, $min, $sec);
|
||||
}
|
||||
|
||||
sub writeLog($$$%) {
|
||||
my ($self, $severity, $msg, %options) = @_;
|
||||
my $withdate = (defined $options{withdate}) ? $options{withdate} : 1;
|
||||
$msg = ($self->{withpid} == 1) ? "$$ - $msg " : $msg;
|
||||
my $newmsg = ($withdate)
|
||||
? $self->get_date . " - $msg" : $msg;
|
||||
|
||||
if (($self->{severity} & $severity) == 0) {
|
||||
return;
|
||||
}
|
||||
if ($self->{log_mode} == 0) {
|
||||
print "$newmsg\n";
|
||||
} elsif ($self->{log_mode} == 1) {
|
||||
if (defined $self->{filehandler}) {
|
||||
print { $self->{filehandler} } "$newmsg\n";
|
||||
}
|
||||
} elsif ($self->{log_mode} == 2) {
|
||||
syslog($severities{$severity}, $msg);
|
||||
}
|
||||
}
|
||||
|
||||
sub writeLogDebug {
|
||||
shift->writeLog(4, @_);
|
||||
}
|
||||
|
||||
sub writeLogInfo {
|
||||
shift->writeLog(2, @_);
|
||||
}
|
||||
|
||||
sub writeLogError {
|
||||
shift->writeLog(1, @_);
|
||||
}
|
||||
|
||||
sub DESTROY {
|
||||
my $self = shift;
|
||||
|
||||
if (defined $self->{filehandler}) {
|
||||
$self->{filehandler}->close();
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,94 @@
|
|||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
package centreon::vmware::script;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use FindBin;
|
||||
use Getopt::Long;
|
||||
use Pod::Usage;
|
||||
use centreon::vmware::logger;
|
||||
|
||||
$SIG{__DIE__} = sub {
|
||||
return unless defined $^S and $^S == 0; # Ignore errors in eval
|
||||
my $error = shift;
|
||||
print "Error: $error";
|
||||
exit 1;
|
||||
};
|
||||
|
||||
sub new {
|
||||
my ($class, $name, %options) = @_;
|
||||
my %defaults =
|
||||
(
|
||||
log_file => undef,
|
||||
severity => "info",
|
||||
noroot => 0,
|
||||
);
|
||||
my $self = {%defaults, %options};
|
||||
|
||||
bless $self, $class;
|
||||
$self->{name} = $name;
|
||||
$self->{logger} = centreon::vmware::logger->new();
|
||||
$self->{options} = {
|
||||
"logfile=s" => \$self->{log_file},
|
||||
"severity=s" => \$self->{severity},
|
||||
"help|?" => \$self->{help}
|
||||
};
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub init {
|
||||
my $self = shift;
|
||||
|
||||
if (defined $self->{log_file}) {
|
||||
$self->{logger}->file_mode($self->{log_file});
|
||||
}
|
||||
$self->{logger}->severity($self->{severity});
|
||||
|
||||
if ($self->{noroot} == 1) {
|
||||
# Stop exec if root
|
||||
if ($< == 0) {
|
||||
$self->{logger}->writeLogError("Can't execute script as root.");
|
||||
die("Quit");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub add_options {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{options} = {%{$self->{options}}, %options};
|
||||
}
|
||||
|
||||
sub parse_options {
|
||||
my $self = shift;
|
||||
|
||||
Getopt::Long::Configure('bundling');
|
||||
die "Command line error" if !GetOptions(%{$self->{options}});
|
||||
pod2usage(-exitval => 1, -input => $FindBin::Bin . "/" . $FindBin::Script) if $self->{help};
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
$self->parse_options();
|
||||
$self->init();
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,56 @@
|
|||
#!/usr/bin/perl
|
||||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
use warnings;
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin";
|
||||
use centreon::script::centreon_vmware;
|
||||
|
||||
centreon::script::centreon_vmware->new()->run();
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
centreon_vmware.pl - a daemon to handle VMWare checks.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
centreon_vmware.pl [options]
|
||||
|
||||
=head1 OPTIONS
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--config-extra>
|
||||
|
||||
Specify the path to the centreon_vmware configuration file (default: /etc/centreon/centreon_vmware.pm).
|
||||
|
||||
=item B<--help>
|
||||
|
||||
Print a brief help message and exits.
|
||||
|
||||
=back
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
B<centreon_vmware.pl> will connect to ESX and/or VirtualCenter.
|
||||
Use the plugin 'apps::vmware::connector::plugin' from: https://github.com/centreon/centreon-plugins
|
||||
|
||||
=cut
|
|
@ -0,0 +1,67 @@
|
|||
name: "perl-VMware-vSphere"
|
||||
arch: "amd64"
|
||||
platform: "linux"
|
||||
version_schema: "none"
|
||||
version: "7.0.0"
|
||||
release: "17698549${DIST}"
|
||||
section: "default"
|
||||
priority: "optional"
|
||||
maintainer: "Centreon <contact@centreon.com>"
|
||||
description: |
|
||||
The vSphere SDK for Perl is a client-side Perl framework that provides an easy-to-use scripting interface to the vSphere API.
|
||||
Administrators and developers who are familiar with Perl can use the vSphere SDK for Perl to automate a wide variety of administrative, provisioning, and monitoring tasks in the vSphere environment.
|
||||
The vSphere SDK for Perl includes ready-to-use utility applications, which you can immediately put to use in your virtual datacenter.
|
||||
The vSphere SDK for Perl installation includes the WS-Management Perl Library, which allows you to write scripts that retrieve CIM data from the ESX host using CIMOM, a service that provides standard CIM management functions over a WBEM (Web-Based Enterprise Management).
|
||||
You can use the SDK to manage ESX 3.0.x, ESX/ESXi 3.5, ESX/ESXi 4.0, ESX/ESXi 4.1, ESXi 5.0, vCenter Server 2.5, vCenter Server 4.0, vCenter Server 4.1, and vCenter Server 5.0.
|
||||
Commit: @COMMIT_HASH@
|
||||
vendor: "vmware"
|
||||
homepage: "https://vmware.com"
|
||||
license: "GPLv2+"
|
||||
|
||||
contents:
|
||||
- src: "../../../vmware-vsphere-cli-distrib/VMware"
|
||||
dst: "@PERL_SITELIB@/VMware"
|
||||
packager: rpm
|
||||
- src: "../../../vmware-vsphere-cli-distrib/VMware"
|
||||
dst: "/usr/share/perl5/VMware"
|
||||
packager: deb
|
||||
|
||||
- src: "../../../vmware-vsphere-cli-distrib/WSMan"
|
||||
dst: "@PERL_SITELIB@/WSMan"
|
||||
packager: rpm
|
||||
- src: "../../../vmware-vsphere-cli-distrib/WSMan"
|
||||
dst: "/usr/share/perl5/WSMan"
|
||||
packager: deb
|
||||
|
||||
overrides:
|
||||
rpm:
|
||||
provides:
|
||||
- perl(VMware::VIRuntime)
|
||||
depends:
|
||||
- perl-XML-LibXML >= 1.58
|
||||
- perl-libwww-perl >= 5.8.05
|
||||
- perl-SOAP-Lite >= 0.67
|
||||
- perl-UUID >= 0.03
|
||||
- perl-Class-MethodMaker >= 2.08
|
||||
deb:
|
||||
depends:
|
||||
- libstat-lsmode-perl
|
||||
- libclass-methodmaker-perl
|
||||
- libuuid-perl
|
||||
- libconvert-binhex-perl
|
||||
- libemail-date-format-perl
|
||||
- libio-sessiondata-perl
|
||||
- libmime-lite-perl
|
||||
- libmime-types-perl
|
||||
- libmime-tools-perl
|
||||
- libmailtools-perl
|
||||
- libnet-smtp-ssl-perl
|
||||
- libsoap-lite-perl
|
||||
- libtext-template-perl
|
||||
- libxml-libxml-perl
|
||||
|
||||
rpm:
|
||||
compression: zstd
|
||||
signature:
|
||||
key_file: ${RPM_SIGNING_KEY_FILE}
|
||||
key_id: ${RPM_SIGNING_KEY_ID}
|
Loading…
Reference in New Issue