#!/bin/bash

# Generic SNMP polling script for network sites
# Usage: ./poll_snmp_site.sh <site_name> <ip1> <ip2> <ip3> ...

if [ $# -lt 2 ]; then
    echo "Usage: $0 <site_name> <ip1> [ip2] [ip3] ..."
    echo "Example: $0 new_hope 10.10.143.11 10.10.143.12 10.10.143.13"
    exit 1
fi

SITE_NAME="$1"
shift
IPS=("$@")

# SNMP community string
COMMUNITY="kdyyJrT0Mm"

# Output file for results
OUTPUT="${SITE_NAME}_results.txt"
> "$OUTPUT"

# Poll each device
for IP in "${IPS[@]}"; do
  echo "Polling $IP..."
  SYSNAME=$(snmpget -v1 -c "$COMMUNITY" -t 2 -r 1 "$IP" 1.3.6.1.2.1.1.5.0 2>/dev/null | awk -F': ' '{print $2}' | tr -d '"')
  
  if [ -n "$SYSNAME" ]; then
    echo "$IP|$SYSNAME" >> "$OUTPUT"
    echo "  Found: $SYSNAME"
  else
    echo "$IP|UNKNOWN" >> "$OUTPUT"
    echo "  Could not retrieve sysName"
  fi
done

echo ""
echo "Results saved to $OUTPUT"
echo ""
echo "To generate Terraform config, run:"
echo "  python3 generate_terraform.py $OUTPUT $SITE_NAME"
