SwitchHero Collector API v1

Python SENDER scriptleri — REST uç noktaları

Başlangıç

Collector API, ağ toplayıcı scriptlerinin veritabanına yazması içindir. Tüm yanıtlar JSON; POST gövdeleri application/json olmalıdır.

Base URL:

https://switchero.net/api/v1/collector

Örnek tam yol: https://switchero.net/api/v1/collector/ip-log

Token: GirişAyarlarCollector API Token

Kimlik doğrulama

Her istekte Bearer token zorunludur.

Authorization: Bearer YOUR_64_CHAR_TOKEN
Content-Type: application/json

Alternatif: X-Api-Token: YOUR_TOKEN

Company (zorunlu)

Her istekte tenant şirket kodu gönderilmelidir (ör. RHBLK). Sunucu otomatik atama yapmaz.

MethodNerede?Örnek
POSTJSON gövdesi"company": "RHBLK"
GETQuery parametresi?company=RHBLK

Python: COLLECTOR_COMPANY in config.pyapi_payload() / api_params().

Python script eşlemesi

ScriptMethodEndpoint
switch_active_checker_services.pyGET/cleanup
switch_active_checker_services.pyGET/ip-log/clear
switch_active_checker_services.pyPOST/ip-log
switch_fan_checker_services.pyGET/fan-log/clear
switch_fan_checker_services.pyPOST/fan-status
switch_auto_save_config_services.pyPOST/switch-config
switch_info_collector_services.pyPOST/switch-info, /switch-interface
switch_mac_checker_services.pyPOST/switch-lldp
makos.pyPOST/switch-mac

IP durumu

GET https://switchero.net/api/v1/collector/cleanup?company=RHBLK

İlgili şirketin closed_ips kayıtlarında alert_rate < 6 olanları siler.

GET https://switchero.net/api/v1/collector/ip-log/clear?company=RHBLK

Sadece o şirketin ip_status_log kayıtlarını siler.

POST https://switchero.net/api/v1/collector/ip-log

{
  "company": "RHBLK",
  "ips": [
    { "ip": "10.0.0.1", "status": "AKTIF" },
    { "ip": "10.0.0.2", "status": "KAPALI" }
  ]
}

status: AKTIF veya KAPALI

Fan izleme

GET https://switchero.net/api/v1/collector/fan-log/clear?company=RHBLK

POST https://switchero.net/api/v1/collector/fan-status

{
  "company": "RHBLK",
  "fans": [
    { "ip": "10.0.0.1", "fan_status": "Normal", "temperature": "42C" }
  ]
}

Konfigürasyon yedekleme

POST https://switchero.net/api/v1/collector/switch-config

{
  "company": "RHBLK",
  "ip_address": "10.0.0.1",
  "config_data": "...",
  "config_type": "running"
}

Switch bilgisi & arayüz

POST https://switchero.net/api/v1/collector/switch-info

{ "company": "RHBLK", "ip", "description", "uptime", "name", "mac_address" }

POST https://switchero.net/api/v1/collector/switch-interface

{ "company": "RHBLK", "ip", "interface_name", "admin_status", "oper_status", "speed" }

LLDP & MAC

POST https://switchero.net/api/v1/collector/switch-lldp

Zorunlu: company, switch_ip, local_port, remote_chassis_id, remote_port_id, remote_sys_name

POST https://switchero.net/api/v1/collector/switch-mac

Zorunlu: company, switch_ip, port, mac_address

Python örneği

Tüm SENDER scriptleri api/SENDER/config.py üzerinden v1 yollarını kullanır.

from config import api_headers, api_url, api_params, api_payload
import requests

# GET — sadece RHBLK loglarını temizle
response = requests.get(
    api_url("clear_ip_log"),
    headers=api_headers(),
    params=api_params(),  # {"company": "RHBLK"}
    timeout=60,
)

# POST — company zorunlu
response = requests.post(
    api_url("save_all_ips"),
    json=api_payload({
        "ips": [
            {"ip": "10.0.0.1", "status": "AKTIF"},
        ],
    }),
    headers=api_headers(),
    timeout=120,
)

Hata kodları

HTTPAnlam
401Token eksik veya geçersiz
404Geçersiz yol (eski .php uçları desteklenmez)
400company eksik veya hatalı gövde
500Sunucu hatası
Web API (oturum) — Giriş sonrası /api/switch-history vb. collector token ile karıştırılmamalıdır.