Skip to content

Instantly share code, notes, and snippets.

@q1x
q1x / snmp-discovery
Created February 19, 2015 12:24
snmp-discovery
#!/bin/bash
#
# This script can be used to perform Zabbix Low-Level Discoveries of
# SNMP hosts on the network via the 'nmap', 'snmpget' and 'host' utilities.
#
# Advantages over normal network discovery:
# * Faster!
# * We can fetch the hostname via SNMP (no more IP based names when PTR records are missing)
# * We can use the highly flexible 'nmap' targetting
#
import sys
if not ('zabbix-tools-python-modules.zip' in sys.path):
sys.path.insert(0, 'packages.zip')
import getpass
from pyzabbix import ZabbixAPI
u = raw_input("Username: ")
p = getpass.getpass()
print "Connecting to zabbix"
zapi = ZabbixAPI("http://127.0.0.1/zabbix")
zapi.login(u, p)
<?php
// define the namespaces that we are interested in
$ns = array
(
'content' => 'http://purl.org/rss/1.0/modules/content/',
'wfw' => 'http://wellformedweb.org/CommentAPI/',
'dc' => 'http://purl.org/dc/elements/1.1/'
);
<?php
// define the namespaces that we are interested in
$ns = array
(
'content' => 'http://purl.org/rss/1.0/modules/content/',
'wfw' => 'http://wellformedweb.org/CommentAPI/',
'dc' => 'http://purl.org/dc/elements/1.1/'
);
#!/bin/bash
# Set path
PATH=/opt/zabbix-gnomes/:$PATH
# Set params
ZGROUPS="05_Core_Network 06_User_Network"
# Loop through hosts
for line in $(zgetinventory.py -G $ZGROUPS -F name | sed 1d); do
@q1x
q1x / stack_inv.sh
Last active December 16, 2015 08:53
#!/bin/bash
# Set path
PATH=/opt/zabbix-gnomes/:$PATH
# Zabbix server
ZBXSERV="127.0.0.1"
# Set params
TEMPLATE="Template Cisco Catalyst Stack"
SERIAL_ITEMKEY="cswSwitchSerialNumber"
SELECT item.title,year.attribute_val,item.s_item_type,GROUP_CONCAT(item_attribute.lookup_attribute_val SEPARATOR ', '),DATE(item_instance.update_on) INTO OUTFILE '/tmp/opendb_export.csv' FIELDS TERMINATED BY ';' ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\n' FROM item LEFT JOIN item_instance ON item.id=item_instance.item_id LEFT JOIN item_attribute ON item.id=item_attribute.item_id LEFT JOIN (SELECT item_id,attribute_val FROM item_attribute WHERE s_attribute_type="YEAR") year on item.id=year.item_id WHERE (item.s_item_type="DVD" AND item_attribute.s_attribute_type="DVD_REGION") OR (item.s_item_type="BLU-RAY" AND item_attribute.s_attribute_type="BD-REGION") GROUP BY item_attribute.item_id ORDER BY item_instance.update_on ASC;
@q1x
q1x / up_discovery.sh
Last active December 16, 2015 11:28
Discoveries
#!/bin/bash
#
# This script discovers only interfaces with Admin status "up".
#
COMMUNITY="$1"
IP="$2"
# Set ifDescr tree
IFDESC=".1.3.6.1.2.1.2.2.1.2"
#!/bin/bash
#
# This script counts the number of returned lines from an SNMP walk.
#
COMMUNITY="$1"
IP="$2"
OID="$3"
FILTER="$4"
# Disable mibs to save time
@q1x
q1x / .pythonrc
Created December 21, 2015 14:58
zabbix pythonrc
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: set ft=python :
try:
import readline
import ConfigParser
import os
import os.path
import sys