Forked from cluther/zenoss-shell-functions
Last active
December 16, 2015 17:09
Revisions
-
rothwerx revised this gist
Apr 26, 2013 . 1 changed file with 24 additions and 22 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,7 @@ #!/bin/sh # Source this file # Your Zenoss server settings. ZENOSS_URL="http://localhost:8080" ZENOSS_USERNAME="admin" @@ -133,34 +135,34 @@ zenoss_add_redundant_policy_to_service () { "{\"contextUid\":\"global\",\"uid\":\"/zport/dmd/DynamicServices$SERVICE_PATH\",\"policyType\":\"Availability\",\"data\":{\"state\":\"ATRISK\",\"triggerType\":\"policyThresholdTrigger\",\"threshold\":1,\"dependentState\":\"DOWN\"}}" } #Example usages of the bash helper functions. # echo "Adding UCS." # zenoss_add_ucs ucs1 zenoss zenoss # echo "Adding vCenter." # zenoss_add_vcenter vcenter1 zenoss zenoss # echo "Adding standard device." # zenoss_add_device n7k1 "/Network/Cisco/Nexus" #Extended to show adding of service organizers, services and elements to #services. #Service Organizers # zenoss_add_service_organizer "/" "Datacenters" # zenoss_add_service_organizer "/Datacenters" "DC1" # zenoss_add_service_organizer "/Datacenters/DC1" "Routers" #Access Routers # zenoss_add_service "/Datacenters/DC1/Routers" "Access Routers" # zenoss_add_redundant_policy_to_service "/Datacenters/DC1/Routers/Access Routers" # zenoss_add_element_to_service \ # "/Datacenters/DC1/Routers/services/Access Routers" \ # "/zport/dmd/Devices/CiscoUCS/devices/TB1-USCM/hw/fabricinterconnects/sys_switch-A" # zenoss_add_element_to_service \ # "/Datacenters/DC1/Routers/services/Access Routers" \ # "/zport/dmd/Devices/CiscoUCS/devices/TB1-USCM/hw/fabricinterconnects/sys_switch-B" -
rothwerx renamed this gist
Apr 26, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
cluther created this gist
Feb 24, 2012 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,166 @@ #!/bin/sh # Your Zenoss server settings. ZENOSS_URL="http://localhost:8080" ZENOSS_USERNAME="admin" ZENOSS_PASSWORD="zenoss" # Generic call to make Zenoss JSON API calls easier on the shell. zenoss_api () { ROUTER_ENDPOINT=$1 ROUTER_ACTION=$2 ROUTER_METHOD=$3 DATA=$4 if [ -z "${DATA}" ]; then echo "Usage: zenoss_api <endpoint> <action> <method> <data>" return 1 fi curl \ -u "$ZENOSS_USERNAME:$ZENOSS_PASSWORD" \ -X POST \ -H "Content-Type: application/json" \ -d "{\"action\":\"$ROUTER_ACTION\",\"method\":\"$ROUTER_METHOD\",\"data\":[$DATA], \"tid\":1}" \ "$ZENOSS_URL/zport/dmd/$ROUTER_ENDPOINT" \ >/dev/null 2>&1 } # Helper call for adding standard device types. zenoss_add_device() { DEVICE_HOSTNAME=$1 DEVICE_CLASS=$2 if [ -z "$DEVICE_CLASS" ]; then echo "Usage: zenoss_add_device <host> <device class>" return 1 fi zenoss_api device_router DeviceRouter addDevice "{\"deviceName\":\"$DEVICE_HOSTNAME\",\"deviceClass\":\"$DEVICE_CLASS\",\"collector\":\"localhost\",\"model\":true,\"title\":\"\",\"productionState\":\"1000\",\"priority\":\"3\",\"snmpCommunity\":\"\",\"snmpPort\":161,\"tag\":\"\",\"rackSlot\":\"\",\"serialNumber\":\"\",\"hwManufacturer\":\"\",\"hwProductName\":\"\",\"osManufacturer\":\"\",\"osProductName\":\"\",\"comments\":\"\"}" } # Helper call for adding UCS Managers. zenoss_add_ucs () { UCS_HOST=$1 UCS_USERNAME=$2 UCS_PASSWORD=$3 if [ -z "$UCS_PASSWORD" ]; then echo "Usage: zenoss_add_ucs <host> <username> <password>" return 1 fi zenoss_api ciscoucs_router CiscoUCSRouter addCiscoUCS "{\"host\":\"$UCS_HOST\",\"username\":\"$UCS_USERNAME\",\"password\":\"$UCS_PASSWORD\",\"port\":\"80\",\"useSSL\":false,\"collector\":\"localhost\"}" } # Helper call for adding VMware vCenters. zenoss_add_vcenter () { VCENTER_HOST=$1 VCENTER_USERNAME=$2 VCENTER_PASSWORD=$3 if [ -z "$VCENTER_PASSWORD" ]; then echo "Usage: zenoss_add_vcenter <host> <username> <password>" return 1 fi zenoss_api vmware_router VMwareRouter addVMwareInfrastructure "{\"id\":\"$VCENTER_HOST\",\"host\":\"$VCENTER_HOST\",\"useSsl\":true,\"username\":\"$VCENTER_USERNAME\",\"password\":\"$VCENTER_PASSWORD\",\"collector\":\"localhost\"}" } # Helper call for adding service organizers. zenoss_add_service_organizer () { ORGANIZER_BASE=$1 ORGANIZER_NAME=$2 if [ -z "$ORGANIZER_NAME" ]; then echo "Usage: zenoss_add_service_organizer <base> <name>" return 1 fi zenoss_api enterpriseservices_router EnterpriseServicesRouter addOrganizer \ "{\"id\":\"$ORGANIZER_NAME\",\"contextUid\":\"/zport/dmd/DynamicServices$ORGANIZER_BASE\"}" } # Helper call for adding a service. zenoss_add_service () { SERVICE_BASE=$1 SERVICE_NAME=$2 if [ -z "$SERVICE_NAME" ]; then echo "Usage: zenoss_add_service <base> <name>" return 1 fi zenoss_api enterpriseservices_router EnterpriseServicesRouter addNode \ "{\"id\":\"$SERVICE_NAME\",\"contextUid\":\"/zport/dmd/DynamicServices$SERVICE_BASE\"}" } # Helper call for adding an element to a service. zenoss_add_element_to_service () { SERVICE_PATH=$1 ELEMENT_URL=$2 if [ -z "$ELEMENT_URL" ]; then echo "Usage: zenoss_add_element_to_service <service_path> <element_url>" return 1 fi zenoss_api enterpriseservices_router EnterpriseServicesRouter addToDynamicService \ "{\"targetUid\":\"/zport/dmd/DynamicServices$SERVICE_PATH\",\"uids\":[\"$ELEMENT_URL\"]}" } # Helper call for adding a redundant policy to a service. zenoss_add_redundant_policy_to_service () { SERVICE_PATH=$1 if [ -z "$SERVICE_PATH" ]; then echo "Usage: zenoss_add_redundant_policy_to_service <service_path" return 1 fi # 100% down == down zenoss_api \ enterpriseservices_router \ EnterpriseServicesRouter \ addStateTrigger \ "{\"contextUid\":\"global\",\"uid\":\"/zport/dmd/DynamicServices$SERVICE_PATH\",\"policyType\":\"Availability\",\"data\":{\"state\":\"DOWN\",\"triggerType\":\"policyPercentageTrigger\",\"threshold\":100,\"dependentState\":\"DOWN\"}}" # 1 down == at risk zenoss_api \ enterpriseservices_router \ EnterpriseServicesRouter \ addStateTrigger \ "{\"contextUid\":\"global\",\"uid\":\"/zport/dmd/DynamicServices$SERVICE_PATH\",\"policyType\":\"Availability\",\"data\":{\"state\":\"ATRISK\",\"triggerType\":\"policyThresholdTrigger\",\"threshold\":1,\"dependentState\":\"DOWN\"}}" } # Example usages of the bash helper functions. echo "Adding UCS." zenoss_add_ucs ucs1 zenoss zenoss echo "Adding vCenter." zenoss_add_vcenter vcenter1 zenoss zenoss echo "Adding standard device." zenoss_add_device n7k1 "/Network/Cisco/Nexus" # Extended to show adding of service organizers, services and elements to # services. # Service Organizers zenoss_add_service_organizer "/" "Datacenters" zenoss_add_service_organizer "/Datacenters" "DC1" zenoss_add_service_organizer "/Datacenters/DC1" "Routers" # Access Routers zenoss_add_service "/Datacenters/DC1/Routers" "Access Routers" zenoss_add_redundant_policy_to_service "/Datacenters/DC1/Routers/Access Routers" zenoss_add_element_to_service \ "/Datacenters/DC1/Routers/services/Access Routers" \ "/zport/dmd/Devices/CiscoUCS/devices/TB1-USCM/hw/fabricinterconnects/sys_switch-A" zenoss_add_element_to_service \ "/Datacenters/DC1/Routers/services/Access Routers" \ "/zport/dmd/Devices/CiscoUCS/devices/TB1-USCM/hw/fabricinterconnects/sys_switch-B"