softlayer / softlayer-python

A set of Python libraries that assist in calling the SoftLayer API.
http://softlayer.github.io/softlayer-python/
MIT License
152 stars 195 forks source link

how to get fortigate device detailed information #1012

Closed sdputurn closed 4 years ago

sdputurn commented 6 years ago

Hi team, we are using Softlayer for our infrastructure. to record Configuration Items CI inventory for servers in SL. we need device information. i am not able to get device information for fortigate devices.

I have tried below:

  1. SoftLayer_Account::getHardware this give me vyatta servers but not fortigate)
  2. firewall manager (FirewallManager) but this gives me only the vlans information Could you please help me where can i get the fortigate devices information such as model, manufacturer, serial number, mac address.(i used to get these details for vyatta firewalls using python apis)

thanks Sandeep

allmightyspiff commented 6 years ago

Example for getting serial number for fortigate

FernandoOjeda commented 6 years ago

Using the softlayer api you can only get a general information of the Firewall (fortigate) as vlan, router, subnets, where the firewall was added and the credentials to access to the fortigate server such as username, password and Management ip, as shown in the control portal.

In order to obtain data such as serial, model, manufacturer, etc., you have to enter to the "fortigate" server with the credentials mentioned above provided by the softlayer api or the portal control.

You can use this python example to obtain the credentials and the ip management of the fortigate and you will be able to enter to the server as in the image below.

"""
GetObject Network_Vlan_Firewall
getObject returns a SoftLayer_Network_Vlan_Firewall object. You can only get objects for vlans attached to your account
that have a network firewall enabled.

Important manual pages:
https://softlayer.github.io/reference/services/SoftLayer_Network_Vlan_Firewall/getObject/
https://softlayer.github.io/reference/datatypes/SoftLayer_Network_Vlan_Firewall/

License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer

# For nice debug output:
from pprint import pprint as pp

# Your SoftLayer API username and key.
API_USERNAME = 'set me'

# Generate one at https://control.softlayer.com/account/users
API_KEY = 'set me'

firewallId = 11111

objectMask = 'mask[billingItem,customerManagedFlag,fullyQualifiedDomainName,managementCredentials,networkVlan[id,' \
             'firewallInterfaces,primaryRouter[hostname,id],vlanNumber],primaryIpAddress, bypassRequestStatus]'

client = SoftLayer.create_client_from_env(
    username=API_USERNAME,
    api_key=API_KEY
)

try:

    orderStatus = client['SoftLayer_Network_Vlan_Firewall'].getObject(mask = objectMask, id = firewallId)
    print(orderStatus)

except SoftLayer.SoftLayerAPIError as e:
    pp('Unable to get the firewall information faultCode=%s, faultString=%s'
       % (e.faultCode, e.faultString))

You will get a response like this example:

{
"primaryIpAddress": "11.111.111.111",
"billingItem": {
"allowCancellationFlag": 1,
"categoryCode": "vlan_firewall",
"description": "FortiGate Security Appliance",
"id":11111
},
"managementCredentials": {
"createDate": "2018-07-31T15:16:23-06:00",
"id": 2222222,
"modifyDate": "2018-07-31T15:16:23-06:00",
"password": "password12345",
"port": 23,
"softwareId": 1111111,
"username": "SL45454"
}

Use the "primaryIpAddress" as the url and the credential username and password to login to the fortigate server.

fortigate

sdputurn commented 6 years ago

@allmightyspiff thanks for the update. when i open the link i get error - "This card may be on a private board. If someone gave you this link, they may need to invite you to one of their boards or teams."

sdputurn commented 6 years ago

@FernandoOjeda thanks for the update. but this will be difficult for me. I am Inventory owner, my job is to get the device details and load them to our inventory database. I was using SL api's to fetch these details and load them. I am not the system owner and should not ssh to these boxes.

is there any other possible solution? if not (i guess this is what you mentioned in your reply), i am happy to close this ticket.

allmightyspiff commented 6 years ago

@sdputurn I'll double check because i thought we provided the serial from the API.

allmightyspiff commented 6 years ago

Aside from logging into the fortigate, it doesn't look like the serial is available in the API directly.

If you are just keeping track of inventory, the ID field is unique for all firewalls. Or the billingItem->orderItemId might also be useful in keeping track of items.