summaryrefslogtreecommitdiff
path: root/src/op_mode/snmp.py
diff options
context:
space:
mode:
authorKim Hagen <kim.sidney@gmail.com>2018-07-02 11:07:30 +0200
committerKim Hagen <kim.sidney@gmail.com>2018-07-02 11:07:30 +0200
commitf589232485ea72003b866093a6fbd4c8aac8f8f8 (patch)
tree6494934d6caade96b2887928bc4ff921a8d9ca21 /src/op_mode/snmp.py
parent48596dcce9e431e448eb8684dc55d922bf7fa2c9 (diff)
downloadvyos-salt-minion-f589232485ea72003b866093a6fbd4c8aac8f8f8.tar.gz
vyos-salt-minion-f589232485ea72003b866093a6fbd4c8aac8f8f8.zip
rework for one script
Diffstat (limited to 'src/op_mode/snmp.py')
-rwxr-xr-xsrc/op_mode/snmp.py77
1 files changed, 0 insertions, 77 deletions
diff --git a/src/op_mode/snmp.py b/src/op_mode/snmp.py
deleted file mode 100755
index e08441f..0000000
--- a/src/op_mode/snmp.py
+++ /dev/null
@@ -1,77 +0,0 @@
-#!/usr/bin/env python3
-#
-# Copyright (C) 2018 VyOS maintainers and contributors
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 2 or later as
-# published by the Free Software Foundation.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-#
-# File: snmp.py
-# Purpose:
-# Show SNMP community/remote hosts
-# Used by the "run show snmp community" commands.
-
-import os
-import sys
-import argparse
-
-from vyos.config import Config
-
-config_file_daemon = r'/etc/snmp/snmpd.conf'
-
-parser = argparse.ArgumentParser(description='Retrieve infomration from running SNMP daemon')
-parser.add_argument('--allowed', action="store_true", help='Show available SNMP communities')
-parser.add_argument('--community', action="store", help='Show status of given SNMP community', type=str)
-parser.add_argument('--host', action="store", help='SNMP host to connect to', type=str, default='localhost')
-
-config = {
- 'communities': [],
-}
-
-def read_config():
- with open(config_file_daemon, 'r') as f:
- for line in f:
- # Only get configured SNMP communitie
- if line.startswith('rocommunity') or line.startswith('rwcommunity'):
- string = line.split(' ')
- # append community to the output list only once
- c = string[1]
- if c not in config['communities']:
- config['communities'].append(c)
-
-def show_all():
- if len(config['communities']) > 0:
- print(' '.join(config['communities']))
-
-def show_community(c, h):
- print('Status of SNMP community {0} on {1}'.format(c, h), flush=True)
- os.system('/usr/bin/snmpstatus -t1 -v1 -c {0} {1}'.format(c, h))
-
-if __name__ == '__main__':
- args = parser.parse_args()
-
- # Do nothing if service is not configured
- c = Config()
- if not c.exists_effective('service snmp'):
- print("SNMP service is not configured")
- sys.exit(0)
-
- read_config()
-
- if args.allowed:
- show_all()
- sys.exit(1)
- elif args.community:
- show_community(args.community, args.host)
- sys.exit(1)
- else:
- parser.print_help()
- sys.exit(1)