grep recursively against known filenames

Sometimes you need to grep for a phrase in an unwieldy directory. Recursion makes this easy, but it could be slow if there are a lot of files.

If you know part of the filename you can limit which files are grepped by using a glob include. There is also an exclude option.

I frequently need to search for an IP address in our syslog server. I’m not sure where that address might show up, but since the syslog files are datetime stamped, I can restrict the logfiles that are grepped.

grep "10.9.8.7" --include=2021-08-30* --recursive 
This will grep recursively for the phrase “10.9.8.7” but only in logfiles that start with 2021-08-30*

Change default screen in Nagios Core 4.4.5

The main default screen in Nagios does not provide any useful host or service information. This can easily be changed.

Edit

/usr/local/nagios/share/index.php

Towards the top, look for the highlighted line:

<?php
// Allow specifying main window URL for permalinks, etc.
$url = 'main.php';

Change this to the page of your choice. CGI rendered pages can be used, be sure to qualify the path…

$url = 'cgi-bin/status.cgi?hostgroup=all&style=hostdetail';

or

$url = 'cgi-bin/tac.cgi';

…are two common choices.

 

From this:

To this:

 

Python script, SolarWinds job of Cisco “show modules” to CSV stdout

This script takes the job output from a SolarWinds report with “show modules” run against Cisco 4500 series switches and turns it into a CSV file with:

switch name, module number, port count, card type, modele, serial number

Output is sent to stdout. Capture and redirect as needed.

Any invalid characters, including ‘,’s, in the original output are replaced with a ‘~’ so as not to throw off the CSV output.

The input file is a single SolarWinds job report containing the response that should look something like this:

SolarWinds Network Configuration Manager
Scheduled Job Notification

___________________________________________________________________________

1/14/2020 4:23:53 PM : Started show modules

Execute Command Script on Devices
33 devices selected

Devices: 33
Errors: 0
___________________________________________________________________________

TEST_SWITCH_01 (192.168.100.1):

show mod
Chassis Type : WS-C4506-E
Power consumed by backplane : 0 Watts
Mod Ports Card Type Model Serial No.
---+-----+--------------------------------------+------------------+-----------
1 6 Sup 7L-E 10GE (SFP+), 1000BaseX (SFP) WS-X45-SUP7L-E CATxxxxxxWx
2 48 10/100/1000BaseT UPOE E Series WS-X4748-UPOE+E CAT2xxxxxxx
3 48 10/100/1000BaseT UPOE E Series WS-X4748-UPOE+E CATxxx9xxxx
4 48 100/1000/2500/5000/10GBaseT UPOE E Ser WS-X4748-12X48U+E CATxxxxxxxA
5 48 100/1000/2500/5000/10GBaseT UPOE E Ser WS-X4748-12X48U+E CATxx5xxxxx
6 48 100/1000/2500/5000/10GBaseT UPOE E Ser WS-X4748-12X48U+E CATx1xxxxxx
M MAC addresses Hw Fw Sw Status
--+--------------------------------+---+------------+----------------+---------
1 xxxx.xxxx.xxxx to xxxx.xxxx.xxxx 3.0 15.0(1r)SG10 03.08.06.E Ok
2 xxxx.xxxx.xxxx to xxxx.xxxx.xxxx 1.1 Ok
3 xxxx.xxxx.xxxx to xxxx.xxxx.xxxx 1.1 Ok
4 xxxx.xxxx.xxxx to xxxx.xxxx.xxxx 1.1 0.0 Ok
5 xxxx.xxxx.xxxx to xxxx.xxxx.xxxx 1.1 0.0 Ok
6 xxxx.xxxx.xxxx to xxxx.xxxx.xxxx 1.1 0.0 Ok
Mod LinecardMode
----+---------------------------------------------------------------------
4 1
5 1
6 1

___________________________________________________________________________

TEST_SWITCH_02 (192.168.100.2):

[...]

___________________________________________________________________________
1/14/2020 4:24:28 PM : Completed show modules
Execution time : 35 seconds
___________________________________________________________________________

Python script, converts Cisco CDP output to csv output

Download python script here: cdp2csv_stdout

# This script takes the output of Cisco's "show cdp neighbors" and
# converts it to a csv formatted output.
#
# Usage:
#
# This script assumes the devices name is located in the first part of
# the filename. i.e. [device_name].[fqdn].[extension]
#
# There are two parts to this script;
# 1) Load the cdp_nei file and parse through it.
# Sometimes data is split in two lines, sometimes it's all on one.
# So we loop through the file, find what we think is valuable, and
# put all data for one neighbor on a single line.
# 2) Loop through the lines of data, pull out the individual parts of
# data elements, print in csv format.

$cdp2csv_stdout.py -h
usage: cdp2csv_stdout.py [-h] [-c] [-n LOCAL_DEV_NAME] [-dv DEBUG_LEVEL] filename

This script converts the results of 'show cdp neighbor' and turns it into csv
output. CSV data is sent to stdout, so redirect or pipe as needed.

positional arguments:
filename The name of the file which contains the output of 'show
cdp neighbor'

optional arguments:
-h, --help show this help message and exit
-c Seperate data elements by a comma (',') rather than a
tab. Tab is default.
-n LOCAL_DEV_NAME Set the local hostname. If this flag is NOT set we assume
the first part of the filename is the local node name.
-dv DEBUG_LEVEL Turn on debug verbosity level. '0' is off (default). This
will invalidate the CSV output structure, but is useful
for troubleshooting.

F5 LTM Monitoring Active/Standby status

Monitor F5 LTM Active/Standby status via SNMP:

Use SNMPWALK to get all instances of Cluster High Availability Status:

[nagios1]# snmpwalk -v 2c -c [community string] F5HOST1 F5-BIGIP-SYSTEM-MIB::sysClusterMbrHaState
F5-BIGIP-SYSTEM-MIB::sysClusterMbrHaState."default".1 = INTEGER: standby(3)
F5-BIGIP-SYSTEM-MIB::sysClusterMbrHaState."default".2 = INTEGER: unknown(0)
F5-BIGIP-SYSTEM-MIB::sysClusterMbrHaState."default".3 = INTEGER: unknown(0)
F5-BIGIP-SYSTEM-MIB::sysClusterMbrHaState."default".4 = INTEGER: unknown(0)

[nagios1]# snmpwalk -v 2c -c [community string] F5HOST2 F5-BIGIP-SYSTEM-MIB::sysClusterMbrHaState
F5-BIGIP-SYSTEM-MIB::sysClusterMbrHaState."default".1 = INTEGER: active(4)
F5-BIGIP-SYSTEM-MIB::sysClusterMbrHaState."default".2 = INTEGER: unknown(0)
F5-BIGIP-SYSTEM-MIB::sysClusterMbrHaState."default".3 = INTEGER: unknown(0)
F5-BIGIP-SYSTEM-MIB::sysClusterMbrHaState."default".4 = INTEGER: unknown(0)