Ubuntu – ZTACS Limited http://ztacs.com Thu, 17 May 2018 10:13:09 +0000 en-US hourly 1 https://wordpress.org/?v=5.6 http://ztacs.com/wp-content/uploads/2018/03/cropped-ztacs_logo.fw_-32x32.png Ubuntu – ZTACS Limited http://ztacs.com 32 32 How to set up multitenancy @ Appdynamics Controller http://ztacs.com/how-to-set-up-multitenancy-appdynamics-controller/ Thu, 17 May 2018 10:13:09 +0000 http://www.solutioning.eu/?p=1019 Setting up multitenancy in Appdynamics is relatively easy. This is basically a setting at the controller’s admin console not to be confused with the standard console. You can access your controller admin console at  http://hostname:8090/controller/admin.jsp

Once you are logged into the controller’s admin backend click on Controller Settings, then locate multitenant.controller setting and set it to true. Please note that once you set your controller to multitenant mode it can not be switched back anymore.

Click Account Settings to and click Add set up a new customer account. You have to specify the  account admin user, its password.

Also specify the number of licenses you want to use for this account and the account’s name.

Once the account is set up you can log off this console and try logging in to your Appdynamics admin panel by visiting https://hostname:8090.

You should see a new field on the login screen asking for the account name you would like use along with the user id and password. Specify your recently created account name, the account admin user and its password to log in.

You should see an empty console when you log in just like this one below.

If you would like to add agents to this newly created account you will have to use the new account name and its account access key ( can be found at the account setup in the controller admin console ) at installation time or just simply change these settings in the controller-info.xml if you already have agents on those servers. Using separate account name and account access key for each customer is how Appdynamics separates one account from an other.

]]>
Installing Appdynamics Machine Agent on Ubuntu 16.04.4 http://ztacs.com/installing-appdynamics-machine-agent-on-ubuntu-16-04-4/ Wed, 16 May 2018 13:32:31 +0000 http://www.solutioning.eu/?p=990 Downloading and installing the Appdynamics Machine Agent

We have recently set up a test environment with a PHP/MySQL based test Ubuntu 16.04.4 server. We will now set up monitoring for Linux OS, PHP 7.0 and MySQL.

The first step is downloading the machine agent. Open your Appdynamics console and select the Getting Started Wizard.

Then click the Server button on the What do you want to monitor? screen.

At the next screen check if the connection details are correct then click the click here to download  button to acquire the Machine Agent.

Upload the downloaded zip file to your ubuntu server, unpack it to a desired location. This is where you want to run the machine agent from.

Check if the hostname of the appdynamics server is resolvable by simply pinging it, and also check if you can telnet into the port defined in the Configure the Controller step ( above ). The Machine Agent zip should contain the configuration files pre-configured with all the connection details, so in this case we do not have to do this manually. Run the machine agent as root using the following command:

[Your-agent-director]/bin/machine-agent &

root@HUAPPD001-P1:/app/appdynamics/machineagent/bin# ./machine-agent
Using java executable at /app/appdynamics/machineagent/jre/bin/java
Using Java Version [1.8.0_111] for Agent
Using Agent Version [Machine Agent v4.4.3.1214 GA Build Date 2018-04-28 05:12:10]
[INFO] Agent logging directory set to: [/app/appdynamics/machineagent]
Machine Agent Install Directory :/app/appdynamics/machineagent
Machine Agent Temp Directory :/app/appdynamics/machineagent/tmp
Tasks Root Directory :/app/appdynamics/machineagent/controlchannel
[INFO] Agent logging directory set to: [/app/appdynamics/machineagent]
Redirecting all logging statements to the configured logger
15:05:30.460 [system-thread-0] DEBUG com.appdynamics.common.framework.util.EmbeddedModeSecurityManager - Installed
15:05:30.490 [system-thread-0] INFO com.appdynamics.analytics.agent.AnalyticsAgent - Starting analytics agent with arguments [-p, /app/appdynamics/machineagent/monitors/analytics-agent/conf/analytics-agent.properties, -yr, analytics-agent.yml]
Started AppDynamics Machine Agent Successfully.

Once the agent is started it should automatically show up on the appdynamics console in the servers section.

Click on the machine’s name to open the detailed OS monitoring dashboard.

If you run into connection errors you can check and change the connection settings in the configuration file:

[Your-agent-director]/conf/controller-info.xml

Assign the machine agent automatically to an application and to its tiers and nodes

If you only want to use the machine agent on this server, you can hard wire the Application, Tier and Node details in the contoller-info.xml. Please note that if you use for example the PHP Agent on the same box this might stop the PHP Agent to connect to the controller.

There is no need to create the tiers and nodes manually they will be created on the dashboard automatically. We only added the WordPress_Test_Environment Application before the agent assignment. You will need to add the following to the controller-info.xml configuration file:

<force-agent-registration>true</force-agent-registration>
<application-name>WordPress_Test_Environment</application-name>
<tier-name>WordPress_Server</tier-name>
<node-name>huappd001-p1</node-name>

Change the name of the application, tier and node according to your specifications and restart the agent. Once the agent is restarted navigate into the application and verify if the machine agent has been added successfully.

]]>
How to remotely list Vmware VMs using python and turn off SSL certificate verification http://ztacs.com/how-to-remotely-list-vmware-vms-using-python-and-turn-off-ssl-certificate-verification/ Thu, 09 Mar 2017 12:33:34 +0000 http://www.solutioning.eu/?p=920 Since we are automating a number of things in our environment there was a need to list vms remotely using a script. We tried using PHP or the vmware vi perl toolkit but we couldn’t make any of them work.

The problem with that PHP script we tried to use was that the SSL certificate on the vcenter host doesn’t match the hostname and even though we tried everything it was impossible to turn the SSL certificate verification off. We tried to use this script:

https://gist.github.com/scr34m/3490246

The problem with the VI perl toolkit was that the toolkit is kind of old and requires libraries that are not available any longer. It also requires perl version 5.8 so we had to install an older perl version parallel with the current one. After a day spent trying to get it working we gave it up.

The last option was to use the  VMware vSphere API Python Bindings and the pyvmomi-community-samples.  We did the following:

Determine the python version:

Python 2.7.12 (default, Nov 19 2016, 06:48:10)
 [GCC 5.4.0 20160609] on linux2
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import sys
 >>> print (sys.version)
 2.7.12 (default, Nov 19 2016, 06:48:10)
 [GCC 5.4.0 20160609]
 >>>

Since Python 2.7 doesn’t have PIP ( Pip Installs Packages ) installed by default we had to get that downloaded and installed first.

Download get-pip.py from here
python get-pip.py

This installs PIP. Now we need to download and install the vmware python extensions.

pip install pyvmomi

We also need to install git if it is not already installed

apt-get install git

Now install the community samples part. The libraries will be installed into the directory you issue this command from.

git clone https://github.com/vmware/pyvmomi-community-samples.git

Locate and run getallvms.py to list all vms from your vcenter. It is very important that you run this script from the community samples location otherwise it will fail with the following error:

root@zoltan-VirtualBox-kk:/app/images/IPM/python# python getallvms.py
 Traceback (most recent call last):
 File "getallvms.py", line 27, in <module>
 import tools.cli as cli
 ImportError: No module named cli

Run the command using the following syntax:

python getallvms.py -s [vcentername]  -u [vmwreuser] -p [vmwarepassword]

If your hostname doesn’t match the certificate you will be getting the error below. If it matches you should be seeing the list of vms now.

Traceback (most recent call last):
 File "getallvms.py", line 104, in <module>
 main()
 File "getallvms.py", line 78, in main
 port=int(args.port),
 File "build/bdist.linux-x86_64/egg/pyVim/connect.py", line 836, in SmartConnect
 File "build/bdist.linux-x86_64/egg/pyVim/connect.py", line 718, in __FindSupportedVersion
 File "build/bdist.linux-x86_64/egg/pyVim/connect.py", line 638, in __GetServiceVersionDescription
 File "build/bdist.linux-x86_64/egg/pyVim/connect.py", line 604, in __GetElementTree
 File "/usr/lib/python2.7/httplib.py", line 1057, in request
 self._send_request(method, url, body, headers)
 File "/usr/lib/python2.7/httplib.py", line 1097, in _send_request
 self.endheaders(body)
 File "/usr/lib/python2.7/httplib.py", line 1053, in endheaders
 self._send_output(message_body)
 File "/usr/lib/python2.7/httplib.py", line 897, in _send_output
 self.send(msg)
 File "/usr/lib/python2.7/httplib.py", line 859, in send
 self.connect()
 File "/usr/lib/python2.7/httplib.py", line 1278, in connect
 server_hostname=server_hostname)
 File "/usr/lib/python2.7/ssl.py", line 353, in wrap_socket
 _context=self)
 File "/usr/lib/python2.7/ssl.py", line 601, in __init__
 self.do_handshake()
 File "/usr/lib/python2.7/ssl.py", line 830, in do_handshake
 self._sslobj.do_handshake()
 ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)

There is no way to switch certificate verification off using a command line parameter so the code has to be changed from:

#!/usr/bin/env python
# VMware vSphere Python SDK
# Copyright (c) 2008-2013 VMware, Inc. All Rights Reserved.
#
# 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.

"""
Python program for listing the vms on an ESX / vCenter host
"""

import atexit

from pyVim import connect
from pyVmomi import vmodl
from pyVmomi import vim

import tools.cli as cli


def print_vm_info(virtual_machine):
    """
    Print information for a particular virtual machine or recurse into a
    folder with depth protection
    """
    summary = virtual_machine.summary
    print("Name       : ", summary.config.name)
    print("Template   : ", summary.config.template)
    print("Path       : ", summary.config.vmPathName)
    print("Guest      : ", summary.config.guestFullName)
    print("Instance UUID : ", summary.config.instanceUuid)
    print("Bios UUID     : ", summary.config.uuid)
    annotation = summary.config.annotation
    if annotation:
        print("Annotation : ", annotation)
    print("State      : ", summary.runtime.powerState)
    if summary.guest is not None:
        ip_address = summary.guest.ipAddress
        tools_version = summary.guest.toolsStatus
        if tools_version is not None:
            print("VMware-tools: ", tools_version)
        else:
            print("Vmware-tools: None")
        if ip_address:
            print("IP         : ", ip_address)
        else:
            print("IP         : None")
    if summary.runtime.question is not None:
        print("Question  : ", summary.runtime.question.text)
    print("")


def main():
    """
    Simple command-line program for listing the virtual machines on a system.
    """

    args = cli.get_args()

    try:
        service_instance = connect.SmartConnect(host=args.host,
                                                user=args.user,
                                                pwd=args.password,
                                                port=int(args.port))

        atexit.register(connect.Disconnect, service_instance)

        content = service_instance.RetrieveContent()

        container = content.rootFolder  # starting point to look into
        viewType = [vim.VirtualMachine]  # object types to look for
        recursive = True  # whether we should look into it recursively
        containerView = content.viewManager.CreateContainerView(
            container, viewType, recursive)

        children = containerView.view
        for child in children:
            print_vm_info(child)

    except vmodl.MethodFault as error:
        print("Caught vmodl fault : " + error.msg)
        return -1

    return 0

# Start program
if __name__ == "__main__":
    main()

…to the code below. Changes are highlighted with bold ( might not be easy to see at first )

#!/usr/bin/env python
# VMware vSphere Python SDK
# Copyright (c) 2008-2013 VMware, Inc. All Rights Reserved.
#
# 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.

"""
Python program for listing the vms on an ESX / vCenter host
"""

import atexit
import ssl

from pyVim import connect
from pyVmomi import vmodl
from pyVmomi import vim

import tools.cli as cli


def print_vm_info(virtual_machine):
    """
    Print information for a particular virtual machine or recurse into a
    folder with depth protection
    """
    summary = virtual_machine.summary
    print("Name       : ", summary.config.name)
    print("Template   : ", summary.config.template)
    print("Path       : ", summary.config.vmPathName)
    print("Guest      : ", summary.config.guestFullName)
    print("Instance UUID : ", summary.config.instanceUuid)
    print("Bios UUID     : ", summary.config.uuid)
    annotation = summary.config.annotation
    if annotation:
        print("Annotation : ", annotation)
    print("State      : ", summary.runtime.powerState)
    if summary.guest is not None:
        ip_address = summary.guest.ipAddress
        tools_version = summary.guest.toolsStatus
        if tools_version is not None:
            print("VMware-tools: ", tools_version)
        else:
            print("Vmware-tools: None")
        if ip_address:
            print("IP         : ", ip_address)
        else:
            print("IP         : None")
    if summary.runtime.question is not None:
        print("Question  : ", summary.runtime.question.text)
    print("")


def main():
    """
    Simple command-line program for listing the virtual machines on a system.
    """

    args = cli.get_args()

    try:

        context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
        context.verify_mode = ssl.CERT_NONE

        service_instance = connect.SmartConnect(host=args.host,
                                                user=args.user,
                                                pwd=args.password,
                                                port=int(args.port),
                                                sslContext=context
)

        atexit.register(connect.Disconnect, service_instance)

        content = service_instance.RetrieveContent()

        container = content.rootFolder  # starting point to look into
        viewType = [vim.VirtualMachine]  # object types to look for
        recursive = True  # whether we should look into it recursively
        containerView = content.viewManager.CreateContainerView(
            container, viewType, recursive)

        children = containerView.view
        for child in children:
            print_vm_info(child)

    except vmodl.MethodFault as error:
        print("Caught vmodl fault : " + error.msg)
        return -1

    return 0

# Start program
if __name__ == "__main__":
    main()

This solution was based on code displayed in this discussion:

https://github.com/vmware/pyvmomi/issues/235

]]>