-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from arista-netdevops-community/5.9.4.1
Release 5.9.4.1
- Loading branch information
Showing
12 changed files
with
288 additions
and
42 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
ARISTA-KUBERNETES-MIB DEFINITIONS ::= BEGIN | ||
|
||
IMPORTS | ||
MODULE-IDENTITY, OBJECT-TYPE, Integer32, experimental FROM SNMPv2-SMI; | ||
|
||
k8sEntry MODULE-IDENTITY | ||
LAST-UPDATED "202402270000Z" | ||
ORGANIZATION "Arista Networks" | ||
CONTACT-INFO "[email protected]" | ||
|
||
DESCRIPTION "SNMP KUBERNETES MIB" | ||
REVISION "202402270000Z" | ||
DESCRIPTION "SNMP KUBERNETES MIB" | ||
::= { experimental 53 } | ||
|
||
kubernetesInfo OBJECT IDENTIFIER ::= { k8sEntry 8 } | ||
|
||
nbPodsInRunningState OBJECT-TYPE | ||
SYNTAX Integer32 | ||
MAX-ACCESS read-only | ||
STATUS current | ||
DESCRIPTION "Number of Kubernetes pods in Running state." | ||
::= { kubernetesInfo 0 } | ||
|
||
nbNodesInReadyState OBJECT-TYPE | ||
SYNTAX Integer32 | ||
MAX-ACCESS read-only | ||
STATUS current | ||
DESCRIPTION "Number of Kubernetes nodes in Ready state." | ||
::= { kubernetesInfo 1 } | ||
|
||
k8sNodesInfo OBJECT-TYPE | ||
SYNTAX OCTET STRING | ||
MAX-ACCESS read-only | ||
STATUS current | ||
DESCRIPTION "Kubernetes nodes information." | ||
::= { kubernetesInfo 2 } | ||
|
||
k8sPodsInfo OBJECT-TYPE | ||
SYNTAX OCTET STRING | ||
MAX-ACCESS read-only | ||
STATUS current | ||
DESCRIPTION "Kubernetes pods information." | ||
::= { kubernetesInfo 3 } | ||
|
||
END |
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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
SHELL := /bin/sh | ||
.PHONY: build redeploy-dev redeploy sh | ||
|
||
VERSION := 5.9.4.1 | ||
|
||
build: ## Build the docker image | ||
docker image prune -a -f ;\ | ||
docker build -f docker/Dockerfile --no-cache -t net_snmp_image:latest -t net_snmp_image:$(VERSION) . ;\ | ||
docker save net_snmp_image -o docker/net_snmp_image ;\ | ||
cd docker ;\ | ||
tar -czvf ../net_snmp_image.tar.gz net_snmp_image | ||
|
||
|
||
redeploy-dev: ## Redeploy the snmpd-monitor pod in dev environment (within k8s.io namespace) | ||
kubectl delete -f snmpd-monitor.yaml ;\ | ||
kubectl wait --for=delete pod -l app=snmpd-monitor --timeout=60s ;\ | ||
nerdctl image --namespace=k8s.io rm net_snmp_image:latest ;\ | ||
tar -xf net_snmp_image.tar.gz ;\ | ||
nerdctl image --namespace=k8s.io load -i net_snmp_image ;\ | ||
nerdctl image ls --namespace=k8s.io | grep net_snmp_image ;\ | ||
kubectl apply -f snmpd-monitor.yaml ;\ | ||
kubectl wait --for=condition=ready pod -l app=snmpd-monitor --timeout=60s | ||
kubectl get pod -l app=snmpd-monitor | ||
|
||
redeploy: ## Redeploy the snmpd-monitor pod in default namespace (works only on single-node CVP cluster) | ||
kubectl delete -f snmpd-monitor.yaml ;\ | ||
kubectl wait --for=delete pod -l app=snmpd-monitor --timeout=60s ;\ | ||
nerdctl image rm net_snmp_image:latest ;\ | ||
tar -xf net_snmp_image.tar.gz ;\ | ||
nerdctl image load -i net_snmp_image ;\ | ||
nerdctl image ls | grep net_snmp_image ;\ | ||
kubectl apply -f snmpd-monitor.yaml ;\ | ||
kubectl wait --for=condition=ready pod -l app=snmpd-monitor --timeout=60s | ||
kubectl get pod -l app=snmpd-monitor | ||
|
||
test: ## Test the snmpd-monitor pod. This only works with default SNMP credentials | ||
kubectl exec -it $(shell kubectl get pod -l app=snmpd-monitor -o jsonpath='{.items[0].metadata.name}') -- snmpwalk -v2c -c testing 127.0.0.1:161 1.3.6.1.2.1.1.5.0 ;\ | ||
kubectl exec -it $(shell kubectl get pod -l app=snmpd-monitor -o jsonpath='{.items[0].metadata.name}') -- snmpwalk -v2c -c testing localhost .1.3.6.1.3.53.8.0 ;\ | ||
kubectl exec -it $(shell kubectl get pod -l app=snmpd-monitor -o jsonpath='{.items[0].metadata.name}') -- snmpwalk -v2c -c testing localhost ARISTA-KUBERNETES-MIB::nbNodesInReadyState ;\ | ||
kubectl exec -it $(shell kubectl get pod -l app=snmpd-monitor -o jsonpath='{.items[0].metadata.name}') -- snmpwalk -v2c -c testing localhost ARISTA-KUBERNETES-MIB::k8sNodesInfo ;\ | ||
kubectl exec -it $(shell kubectl get pod -l app=snmpd-monitor -o jsonpath='{.items[0].metadata.name}') -- snmpwalk -v3 -l authPriv -u arista -a SHA-512 -A 'arista1234' -x AES-256 -X 'arista1234' localhost ARISTA-KUBERNETES-MIB::k8sPodsInfo | ||
|
||
sh: ## Open a shell in the snmpd-monitor pod | ||
kubectl exec -it $(shell kubectl get pod -l app=snmpd-monitor -o jsonpath='{.items[0].metadata.name}') -- sh |
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 characters
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 characters
This file was deleted.
Oops, something went wrong.
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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
apiVersion: v1 | ||
clusters: | ||
- cluster: | ||
certificate-authority: /host-root/cvpi/tls/certs/kube-cert.pem | ||
server: https://127.0.0.1:6443 | ||
name: local | ||
contexts: | ||
- context: | ||
cluster: local | ||
user: kubelet | ||
name: kubelet-context | ||
current-context: kubelet-context | ||
kind: Config | ||
preferences: {} | ||
users: | ||
- name: kubelet | ||
user: | ||
client-certificate: /host-root/cvpi/tls/certs/kube-cert.pem | ||
client-key: /host-root/cvpi/tls/certs/kube-cert.pem |
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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#!/usr/bin/python3 -u | ||
|
||
import snmp_passpersist as snmp | ||
|
||
import subprocess | ||
|
||
# Enable logging to a file for debugging purposes | ||
# import logging | ||
# logging.basicConfig(filename='/script_snmp.log', encoding='utf-8', level=logging.DEBUG) | ||
# logging.debug('Init logging for script_snmp.py') | ||
|
||
# The position in the tree where the data will be added - SNMPv2-SMI::experimental network-objects | ||
TREE_POSITION_START = ".1.3.6.1.3.53.8" | ||
|
||
UPDATE_INTERVAL = 60 # Interval in seconds at which the script will be called | ||
|
||
|
||
def call_command(command): | ||
""" | ||
call_command Execute the command as a subprocess and return the output decoded in ascii. | ||
Parameters | ||
---------- | ||
command : list | ||
The command to call as a list (Ex: ['kubectl', 'get', 'nodes', '-o', 'wide']) | ||
Returns | ||
------- | ||
str | ||
The output of the command decoded in ascii | ||
""" | ||
# logging.debug(f"Calling command: '{command}'") | ||
output = subprocess.check_output(command, stderr=subprocess.DEVNULL) | ||
return output.decode("ascii") | ||
|
||
|
||
def count_string_in_cmd_output_and_add_at_position(position_in_tree, commands, string_to_count): | ||
""" | ||
count_string_in_cmd_output_and_add_at_position Execute the command and count the number of times the string_to_count is present in the output and add it to the tree. | ||
Parameters | ||
---------- | ||
position_in_tree : str | ||
Position in the tree to add the data (Ex: '0.' for the first level of the tree) | ||
commands : list | ||
The command to call as a list (Ex: ['kubectl', 'get', 'nodes', '-o', 'wide']). | ||
string_to_count : str | ||
The string to count in the output of the command | ||
Returns | ||
------- | ||
None | ||
""" | ||
info_from_subprocess = call_command(commands) | ||
# logging.debug(f"Info from subprocess: {info_from_subprocess}") | ||
count = info_from_subprocess.count(string_to_count) | ||
# logging.debug(f"Count: {count}") | ||
position = position_in_tree[:-1] # Remove the last dot in position string | ||
pp.add_int(position, count) | ||
|
||
|
||
def add_command_in_tree_at_position(position_in_tree, commands): | ||
""" | ||
add_command_in_tree_at_position Execute the command and add it to the pass persist object at position_in_tree. | ||
Parameters | ||
---------- | ||
position_in_tree : str | ||
Position in the tree to add the data (Ex: '0.' for the first level of the tree) | ||
commands : list | ||
The command to call as a list (Ex: ['kubectl', 'get', 'nodes', '-o', 'wide']). | ||
Returns | ||
------- | ||
None | ||
""" | ||
info_from_subprocess = call_command(commands) | ||
# Split the string into lines | ||
lines = info_from_subprocess.strip().split('\n') | ||
# logging.debug(f"Lines: {lines}") | ||
|
||
# Process each line (excluding the first line of headers) | ||
for index_line, line in enumerate(lines[1:]): | ||
position = position_in_tree + str(index_line) | ||
pp.add_str(position, line) | ||
|
||
def update(): | ||
# try: | ||
|
||
count_string_in_cmd_output_and_add_at_position("0.", ["kubectl", "get", "pods", "--all-namespaces", "--field-selector=status.phase=Running"], "Running") | ||
count_string_in_cmd_output_and_add_at_position("1.", ["kubectl", "get", "nodes"], "Ready") | ||
|
||
add_command_in_tree_at_position("2.", ["kubectl", "get", "nodes", "-o", "wide"]) | ||
add_command_in_tree_at_position("3.", ["kubectl", "get", "pods", "-o", "wide", "--all-namespaces"]) | ||
# except Exception as e: | ||
# logging.error(f"Error: {e}") | ||
|
||
pp=snmp.PassPersist(TREE_POSITION_START) | ||
pp.start(update, UPDATE_INTERVAL) |
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 characters
Binary file not shown.
Binary file not shown.
Oops, something went wrong.