Пример #1
0
def check_vnic_tuple(vnic_and_service):
    tuple_parts = vnic_and_service.split(',')
    local_service_id = tuple_parts[0]
    mac_address = tuple_parts[1]
    check_output = None
    try:
        netns_cmd = 'ip netns exec {} arp -n'.format(local_service_id)
        check_output = 'MAC={}, local_service_id={}\n'\
            .format(mac_address, local_service_id)
        netns_out = subprocess.check_output([netns_cmd],
                                            stderr=subprocess.STDOUT,
                                            shell=True)
        netns_out = binary2str(netns_out)
        check_output += '{}\n'.format(netns_out)
        netns_lines = netns_out.splitlines()
        if not netns_lines or \
                netns_lines[0].endswith('No such file or directory'):
            check_rc = 2
        else:
            mac_found = False
            flags = None
            for l in netns_lines:
                line_parts = l.split()
                line_mac = line_parts[arp_mac_pos]
                if len(line_parts) > arp_mac_pos and line_mac == mac_address:
                    mac_found = True
                    flags = line_parts[arp_flags_pos]
                    break
            if mac_found:
                check_rc = 1 if flags == 'I' else 0
            else:
                check_rc = 2
    except subprocess.CalledProcessError as e:
        check_output = str(e)
        check_rc = 2
    return check_rc, check_output
Пример #2
0
return full text of "vppctl show runtime"
"""

import re
import subprocess

from binary_converter import binary2str

rc = 0
search_pattern = re.compile("^startup-config-process ")

try:
    out = subprocess.check_output(["sudo vppctl show runtime"],
                                  stderr=subprocess.STDOUT,
                                  shell=True)
    out = binary2str(out)
    lines = out.splitlines()
    matching_lines = [l for l in lines if search_pattern.match(l)]
    matching_line = matching_lines[0] if matching_lines else None
    if matching_line and "done" in matching_line.split():
        print(out)
    else:
        rc = 1
        print('Error: failed to find status in ifconfig output: ' + out)
except subprocess.CalledProcessError as e:
    print("Error finding 'vppctl show runtime': {}".format(binary2str(
        e.output)))
    rc = 2

exit(rc)
Пример #3
0
    return parser.parse_args()


args = get_args()

if not args.target:
    raise ValueError('target address must be specified')

rc = 0

try:
    cmd = "ping -c {} -i {} -p {} -w {} -s {} {}{} {}".format(
        args.count, args.interval, args.pattern, args.wait, args.packetsize,
        '-I ' if args.source else '', args.source, args.target)
    out = subprocess.check_output([cmd], stderr=subprocess.STDOUT, shell=True)
    out = binary2str(out)
except subprocess.CalledProcessError as e:
    print("Error doing ping: {}\n".format(binary2str(e.output)))

# find packet loss data
packet_loss_match = re.search('(\d+)[%] packet loss', out, re.M)
if not packet_loss_match:
    out += '\npacket loss data not found'
    rc = 2

# find rtt avg/max data
rtt_results = None
if rc < 2:
    regexp = 'rtt min/avg/max/mdev = [0-9.]+/([0-9.]+)/([0-9.]+)/[0-9.]+ ms'
    rtt_results = re.search(regexp, out, re.M)
    if not rtt_results:
Пример #4
0
"""

import re
import subprocess

from binary_converter import binary2str

NAME_RE = '^[a-zA-Z]*GigabitEthernet'

rc = 0

try:
    out = subprocess.check_output(["sudo vppctl show hardware-interfaces"],
                                  stderr=subprocess.STDOUT,
                                  shell=True)
    out = binary2str(out)
    lines = out.splitlines()
    name_re = re.compile(NAME_RE)
    matching_lines = [l for l in lines if name_re.search(l)]
    matching_line = matching_lines[0] if matching_lines else None
    if matching_line:
        rc = 0 if "up" in matching_line.split() else 2
        print('output from "vppctl show hardware-interfaces":\n{}'.format(out))
    else:
        rc = 2
        print('Error: failed to find pNic in output of '
              '"vppctl show hardware-interfaces": {}'.format(out))
except subprocess.CalledProcessError as e:
    print("Error running 'vppctl show hardware-interfaces': {}".format(
        binary2str(e.output)))
    rc = 2
Пример #5
0
import re
import subprocess

from binary_converter import binary2str


NAME_RE = '^[a-zA-Z]*GigabitEthernet'

rc = 0

try:
    out = subprocess.check_output(["sudo vppctl show hardware-interfaces"],
                                  stderr=subprocess.STDOUT,
                                  shell=True)
    out = binary2str(out)
    lines = out.splitlines()
    name_re = re.compile(NAME_RE)
    matching_lines = [l for l in lines if name_re.search(l)]
    matching_line = matching_lines[0] if matching_lines else None
    if matching_line:
        rc = 0 if "up" in matching_line.split() else 2
        print('output from "vppctl show hardware-interfaces":\n{}'
              .format(out))
    else:
        rc = 2
        print('Error: failed to find pNic in output of '
              '"vppctl show hardware-interfaces": {}'
              .format(out))
except subprocess.CalledProcessError as e:
    print("Error running 'vppctl show hardware-interfaces': {}"
Пример #6
0
Run command: 
ps -aux | grep "\(ovs-vswitchd\|ovsdb-server\)"

OK if for both ovs-vswitchd AND ovsdb-server processes we see '(healthy)'
otherwise CRITICAL

return full text output of the command
"""

import subprocess

from binary_converter import binary2str

rc = 0
cmd = 'ps aux | grep "\(ovs-vswitchd\|ovsdb-server\): monitoring" | ' + \
      'grep -v grep'

try:
    out = subprocess.check_output([cmd], stderr=subprocess.STDOUT, shell=True)
    out = binary2str(out)
    lines = out.splitlines()
    matching_lines = [l for l in lines if '(healthy)']
    rc = 0 if len(matching_lines) == 2 else 2
    print(out)
except subprocess.CalledProcessError as e:
    print("Error finding expected output: {}".format(binary2str(e.output)))
    rc = 2

exit(rc)
Пример #7
0
import subprocess

from binary_converter import binary2str

if len(sys.argv) < 2:
    print('usage: ' + sys.argv[0] + ' <bridge>')
    exit(1)
bridge_name = str(sys.argv[1])

rc = 0

cmd = None
out = ''
try:
    cmd = "brctl showmacs {}".format(bridge_name)
    out = subprocess.check_output([cmd], stderr=subprocess.STDOUT, shell=True)
    out = binary2str(out)
    lines = out.splitlines()
    if not lines or lines[0].endswith('No such device'):
        rc = 2
    else:
        print(out)
except subprocess.CalledProcessError as e:
    rc = 2
    out = str(e)

if rc != 0:
    print('Failed to find vConnector {}:\n{}\n'.format(bridge_name, out))

exit(rc)
Пример #8
0
def nic_not_found(name, output):
    print("Error finding NIC {}{}{}\n".format(name, ': ' if output else '',
                                              output))
    return 2


if len(sys.argv) < 2:
    print('name of interface must be specified')
    exit(2)
nic_name = str(sys.argv[1])

rc = 0

try:
    cmd = 'ip link show | grep -A1 "^[0-9]\+: {}:"'.format(nic_name)
    out = subprocess.check_output([cmd], stderr=subprocess.STDOUT, shell=True)
    out = binary2str(out)
    lines = out.splitlines()
    if not lines:
        rc = nic_not_found(nic_name, '')
    else:
        line = lines[0]
        if ' state UP ' not in line:
            rc = 2
        print(out)
except subprocess.CalledProcessError as e:
    rc = nic_not_found(nic_name, binary2str(e.output))

exit(rc)
Пример #9
0
args = sys.argv
if len(args) < 3:
    print('usage: check_vservice.py <vService type> <vService ID>')
    exit(2)

vservice_type = args[1]
vservice_id = args[2]
netns_cmd = 'sudo ip netns pid {}'.format(vservice_id)
pid = ''
ps_cmd = ''
try:
    out = subprocess.check_output([netns_cmd],
                                  stderr=subprocess.STDOUT,
                                  shell=True)
    out = binary2str(out)
    lines = out.splitlines()
    if not lines:
        print('no matching vservice: {}\ncommand: {}\noutput: {}'.format(
            vservice_id, netns_cmd, out))
        exit(2)
    pid = lines[0]
except subprocess.CalledProcessError as e:
    print("Error running '{}': {}".format(netns_cmd, binary2str(e.output)))
    exit(2)
try:
    ps_cmd = 'ps -uf -p {}'.format(pid)
    out = subprocess.check_output([ps_cmd],
                                  stderr=subprocess.STDOUT,
                                  shell=True)
    ps_out = binary2str(out)