monitoringibm-cloud-infrastructure

Adding basic monitoring package to Virtual Guest via API


Is it possible to add a monitoring package through the Softlayer API? On the portal, I can go into the Monitoring section and Order a "Monitoring Package - Basic", which will associate it with that Virtual Guest.

Is it possible to do this either during the placeOrder call or after the initial placeOrder call (i.e if the customer wants to add Basic Monitoring after the server is provisioned).

I tried to look into examples but they all assumed that there was a monitoring agent available, but it wasn't in my case. I also looked into Going Further with Softlayer part 3 but not sure how to extract the Basic Monitoring package from Product_Package Service.

I'm using Python to do this. I am seeking pointers in associating a Monitoring service during or after creation.


Solution

  • try this:

    """
    Order a Monitoring Package
    
    Build a SoftLayer_Container_Product_Order_Monitoring_Package object for a new
    monitoring order and pass it to the SoftLayer_Product_Order API service to order it
    In this care we'll order a Basic (Hardware and OS) package with Basic Monitoring Package - Linux
    configuration for more details see below
    
    Important manual pages:
    https://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Monitoring_Package
    http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Price
    http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder
    http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder
    http://sldn.softlayer.com/reference/datatypes/SoftLayer_Monitoring_Agent_Configuration_Template_Group
    
    License: http://sldn.softlayer.com/article/License
    Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
    """
    
    import SoftLayer
    
    USERNAME = 'set me'
    API_KEY = 'set me'
    
    """
    Build a skeleton SoftLayer_Container_Product_Order_Monitoring_Package object
    containing the order you wish to place.
    """
    oderTemplate = {
        'complexType': 'SoftLayer_Container_Product_Order_Monitoring_Package',
        'packageId': 0,  # the packageID for order monitoring packages is 0
        'prices': [
            {'id': 2302}  # this is the price for Monitoring Package - Basic ((Hardware and OS))
        ],
        'quantity': 0,  # the quantity for order a service (in this case monitoring package) must be 0
        'sendQuoteEmailFlag': True,
        'useHourlyPricing': True,
        'virtualGuests': [
            {'id': 4906034}  # the virtual guest ID where you want add the monitoring package
        ],
        'configurationTemplateGroups': [
            {'id': 3}  # the templateID for the monitoring group (in this case Basic Monitoring package for Unix/Linux operating system.)
        ]
    }
    
    # Declare the API client to use the SoftLayer_Product_Order API service
    client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
    productOrderService = client['SoftLayer_Product_Order']
    
    """
    verifyOrder() will check your order for errors. Replace this with a call to
    placeOrder() when you're ready to order. Both calls return a receipt object
    that you can use for your records.
    
    Once your order is placed it'll go through SoftLayer's provisioning process.
    """
    try:
        order = productOrderService.verifyOrder(oderTemplate)
        print(order)
    except SoftLayer.SoftLayerAPIError as e:
        print("Unable to verify the order! faultCode=%s, faultString=%s"
              % (e.faultCode, e.faultString))
        exit(1)
    

    this is an example to create an network monitoring

    """
    Create network monitoring
    
    The script creates a monitoring network with Service ping
    in a determinate IP address
    
    Important manual pages
    http://sldn.softlayer.com/reference/services/SoftLayer_Network_Monitor_Version1_Query_Host
    http://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_Monitor_Version1_Query_Host
    
    License: http://sldn.softlayer.com/article/License
    Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
    """
    import SoftLayer.API
    from pprint import pprint as pp
    
    # Your SoftLayer API username and key.
    USERNAME = 'set me'
    API_KEY = 'set me'
    
    
    # The ID of the server you wish to monitor
    serverId = 7698842
    
    """
    ID of the query type which can be found with SoftLayer_Network_Monitor_Version1_Query_Host_Stratum/getAllQueryTypes.
    This example uses SERVICE PING: Test ping to address, will not fail on slow server response due to high latency or
    high server load
    """
    queryTypeId = 1
    
    # IP address on the previously defined server to monitor
    ipAddress = '10.104.50.118'
    
    # Declare the API client
    client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
    networkMonitorVersion = client['SoftLayer_Network_Monitor_Version1_Query_Host']
    
    # Define the SoftLayer_Network_Monitor_Version1_Query_Host templateObject.
    newMonitor = {
        'guestId': serverId,
        'queryTypeId': queryTypeId,
        'ipAddress': ipAddress
    }
    
    # Send the request for object creation and display the return value
    try:
        result = networkMonitorVersion.createObject(newMonitor)
        pp(result)
    except SoftLayer.SoftLayerAPIError as e:
        print("Unable to create new network monitoring "
              % (e.faultCode, e.faultString))
        exit(1)
    

    Regards