
This scenario which the environment using mode IAP. please install requirement below
apt-get install python python-pip nginx git -y
pip-install netmiko prometheus_client
Then create a python script to collect data client per AP as IAP Collector, for example the script name “collect_iap.py” then copy the script below
#!/usr/bin/env pythonfrom netmiko import ConnectHandlerfrom netmiko.ssh_exception import NetMikoTimeoutExceptionfrom netmiko.ssh_exception import AuthenticationExceptionfrom paramiko.ssh_exception import SSHExceptionimport json,time,oswith open('devices_iap') as f:devices_list = f.read().splitlines()for a_device in devices_list:hostname = a_deviceaos_device = {'device_type': 'aruba_os','ip': hostname,'username': 'your_username','password': 'your_password'}# if one of devices down, the script will running next jobtry:net_connect= ConnectHandler(**aos_device)except (AuthenticationException):print 'auth failure ' + hostnamecontinueexcept (NetMikoTimeoutException):print 'IP Timeout ' + hostnamecontinueexcept (EOFError):print 'End of file while attempting device ' + hostnamecontinueexcept (SSHException):print 'SSH not enble ' + hostnamecontinueexcept Exception as unknown_error:print 'unknown error ' + str(unknown_error)continuenet_connect = ConnectHandler(**aos_device)excecute_command = net_connect.send_command("show ap association | in Num")parse_command = excecute_command[12:16]result = "{} ".format(aos_device['ip']) + parse_command + "\n"print resultoutput_file = open("output.txt", "a")output_file.write(result)output_file.close()print "Convert to JSON File"commands = {}with open("output.txt") as fh:for line in fh:command, description = line.strip().split(' ', 1)commands[command] = description.strip()print(json.dumps(commands, indent=2, sort_keys=True))with open('/var/www/html/aruba_iap.json', 'w') as json_file:json.dump(commands, json_file)time.sleep(20)remove_file = os.system("rm -rf output.txt")print "Done"
root@vm-prom-collector:/home/aruba_os# chmod +x collect_iap.py
Define list of devices in /etc/hosts
192.168.232.2 IAP325_02
192.168.232.3 IAP325_03
192.168.232.4 IAP325_04
192.168.232.5 IAP325_05
Make sure the script is running properly
root@vm-prom-collector:/home/aruba_os# python collect_iap.py
Collecting data…..
Convert to JSON File
{
“IAP325_03”: “2”,
“IAP325_03”: “6”,
“IAP325_04”: “0”,
“IAP325_05”: “4”,
}
Done
Create JSON exporter, Actually the script already created by other. Please clone the script from repository
root@vm-prom-collector:/home/rohmat/aruba_os# git clone https://github.com/project-sunbird/prometheus-jsonpath-exporter.git
root@vm-prom-collector:/home/rohmat/aruba_os# cd prometheus-jsonpath-exporter/
root@vm-prom-collector:/home/rohmat/aruba_os/prometheus-jsonpath-exporter# nano example/config_aruba.yml
Copy the script below in /home/rohmat/aruba_os/prometheus-jsonpath-exporter/example/config_aruba.yml
exporter_port: 9158 log_level: info json_data_url: http://192.168.38.60/aruba_os.json metric_name_prefix: aruba metrics: - name: CAP325_02 description: Aruba test path: $.CAP325_02 - name: CAP325_02 description: Aruba test path: $.CAP325_02 - name: CAP325_03 description: Aruba test path: $.CAP325_03 - name: CAP325_04 description: Aruba test path: $.AP325_04
Create linux service in folder /lib/systemd/system, so it can auto start after rebooted
root@vm-prom-collector:/home/rohmat/aruba_os#nano /lib/systemd/sysem/aruba_exporter.service
[Unit] Description=service exporter iap aruba After=multi-user.target [Service] Type=idle ExecStart=/usr/bin/python /opt/prometheus-jsonpath-exporter/app/exporter.py /opt/prometheus-jsonpath-exporter/example/config_aruba.yml [Install] WantedBy=multi-user.target
root@vm-prom-collector:/home/rohmat/aruba_os# systemctl daemon-reload
root@vm-prom-collector:/home/rohmat/aruba_os# system restart aruba_exporter.service
Setup Prometheus & Grafana. I assumse this scenario already setup prometheus server, if you have no environment please follow this step : Prometheus : https://www.booleanworld.com/install-use-prometheus-monitoring/
Grafana : https://grafana.com/docs/installation/debian/
Configure prometheus server to srap data from json exporter, this scenario prometheus server & json exporter in the same server. please add configuration file in /etc/prometheus/prometheus.yml
job_name: 'aruba_os_iap' scrape_interval: 30s static_configs: - targets: ['localhost:9158']
Restart the service prometheus, “systemctl restart prometheus”
Create metrics in Grafana

