def remotely_remove_file(system_ip, filename): args = "rm -rf %s" % filename a = Ansible() response = a.run_module(host_list=[system_ip], module="command", args=args) try: if response['contacted'][system_ip]['rc'] > 0: return False except: return False finally: del a return True
def remotely_copy_file(system_ip, orig, dest): args = "cp %s %s" % (orig, dest) a = Ansible() response = a.run_module(host_list=[system_ip], module="command", args=args) try: if response['contacted'][system_ip]['rc'] > 0: return False except: return False finally: del a return True
def remotely_remove_file(system_ip, filename): args = "rm -rf %s" % filename a = Ansible() response = a.run_module(host_list=[system_ip], module="command", args=args) try: if response["contacted"][system_ip]["rc"] > 0: return False except: return False finally: del a return True
def remotely_copy_file(system_ip, orig, dest): args = "cp %s %s" % (orig, dest) a = Ansible() response = a.run_module(host_list=[system_ip], module="command", args=args) try: if response["contacted"][system_ip]["rc"] > 0: return False except: return False finally: del a return True
def touch_file(system_ip, filename): args = "touch %s" % filename a = Ansible() response = a.run_module(host_list=[system_ip], module="command", args=args) print response try: if response['contacted'][system_ip]['rc'] > 0: return False except: return False finally: del a return True
def touch_file(system_ip, filename): args = "touch %s" % filename a = Ansible() response = a.run_module(host_list=[system_ip], module="command", args=args) print response try: if response["contacted"][system_ip]["rc"] > 0: return False except: return False finally: del a return True
import traceback from tempfile import NamedTemporaryFile import api_log from ansiblemethods.ansiblemanager import Ansible, PLAYBOOKS from ansiblemethods.helper import ansible_is_valid_response from apimethods.utils import is_valid_ipv4, set_owner_and_group, set_file_permissions, set_ossec_file_permissions import re import os import json import stat from collections import namedtuple import StringIO # See PEP8 http://legacy.python.org/dev/peps/pep-0008/#global-variable-names # Pylint thinks that a variable at module scope is a constant _ansible = Ansible() # pylint: disable-msg=C0103 def get_ossec_agent_data(host_list=[], args={}): """ Return the ossec agent data @param host_list: List of ip whose data we need """ return _ansible.run_module(host_list, 'ossec_agent', args) def ossec_win_deploy(sensor_ip, agent_name, windows_ip, windows_username, windows_domain, windows_password): """ @param sensor_ip: The sensor IP from where to deploy the ossec agent @agent_name:
import getpass import sys from ansiblemethods.ansiblemanager import Ansible, PLAYBOOKS from db.methods.system import db_get_systems, get_system_id_from_local from ansiblemethods.system.system import ansible_remove_key_from_known_host_file, ansible_add_system from avconfig.ossimsetupconfig import AVOssimSetupConfigHandler ossim_setup = AVOssimSetupConfigHandler() ansible = Ansible() def add_system_with_new_key(local_system_id, remote_system_ip): number_of_tries = 0 status = False while not status and number_of_tries < 3: number_of_tries += 1 msg = 'Please enter root password for {}:\n '.format(remote_system_ip) password = getpass.getpass(msg) status, result = ansible_add_system(local_system_id, remote_system_ip, password) if not status: print(result) return status def confirm(prompt='Confirm', default=False): """ Prompts for yes or no response from the user. Returns True for yes and False for no. Args:
# You should have received a copy of the GNU General Public License # along with this package; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, # MA 02110-1301 USA # # # On Debian GNU/Linux systems, the complete text of the GNU General # Public License can be found in `/usr/share/common-licenses/GPL-2'. # # Otherwise you can read it here: http://www.gnu.org/licenses/gpl-2.0.txt # from ansiblemethods.ansiblemanager import Ansible, PLAYBOOKS, CONFIG_FILE from ansiblemethods.helper import ansible_is_valid_response ansible = Ansible() def send_email(host, port, sender, recipients,subject, body,user,passwd,use_ssl,attachemnts): """ Send an email. """ args = "host=%s \ port=%s \ sender=%s \ recipients=%s \ subject=\"%s\" \ body=\"%s\" \ user=%s \ passwd=%s \ use_ssl=%s \
import os.path import api_log import uuid from base64 import b64decode from os.path import basename from apiexceptions.ansible import APIAnsibleError, APIAnsibleBadResponse from ansiblemethods.ansiblemanager import Ansible, PLAYBOOKS from ansiblemethods.helper import ( parse_av_config_response, read_file, ansible_is_valid_response, ansible_is_valid_playbook_response, copy_file, remove_file) ansible = Ansible() def get_system_id(system_ip): """ Returns the system Id from a given ip @param system_ip: the host system ip """ host_list = [] host_list.append(system_ip) uuid_regex = re.compile('^[a-fA-F0-9]{8}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{12}$') # 1- Try alienvault-system-id response = ansible.run_module([system_ip], "command", "/usr/bin/alienvault-system-id") success, msg = ansible_is_valid_response(system_ip, response)
# On Debian GNU/Linux systems, the complete text of the GNU General # Public License can be found in `/usr/share/common-licenses/GPL-2'. # # Otherwise you can read it here: http://www.gnu.org/licenses/gpl-2.0.txt # from ansiblemethods.ansiblemanager import Ansible from ansiblemethods.helper import ansible_is_valid_response from apimethods.utils import get_hex_string_from_uuid, get_ip_hex_from_str import api_log import uuid import re ansible = Ansible() def get_server_stats(host, args={}): return ansible.run_module([host], 'av_server', args) def get_remote_server_id_from_server_ip(server_ip): cmd = "echo \"select hex(id) from alienvault.server where server.ip=inet6_aton('%s')\" | ossim-db | tail -1" % server_ip response = ansible.run_module(host_list=[server_ip], module="shell", args=cmd) if server_ip in response['dark']: return False, "Failed to get the remote server ID. %s" % response[
# On Debian GNU/Linux systems, the complete text of the GNU General # Public License can be found in `/usr/share/common-licenses/GPL-2'. # # Otherwise you can read it here: http://www.gnu.org/licenses/gpl-2.0.txt # from ansiblemethods.ansiblemanager import Ansible from ansiblemethods.helper import ansible_is_valid_response from apimethods.utils import get_hex_string_from_uuid, get_ip_hex_from_str import api_log import uuid import re ansible = Ansible() def get_server_stats (host, args = {}): return ansible.run_module ([host], 'av_server', args) def get_remote_server_id_from_server_ip(server_ip): cmd = "echo \"select hex(id) from alienvault.server where server.ip=inet6_aton('%s')\" | ossim-db | tail -1" % server_ip response = ansible.run_module(host_list=[server_ip], module="shell", args=cmd) if server_ip in response['dark']: return False, "Failed to get the remote server ID. %s" % response['dark'][server_ip]['msg']
# You should have received a copy of the GNU General Public License # along with this package; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, # MA 02110-1301 USA # # # On Debian GNU/Linux systems, the complete text of the GNU General # Public License can be found in `/usr/share/common-licenses/GPL-2'. # # Otherwise you can read it here: http://www.gnu.org/licenses/gpl-2.0.txt # from ansiblemethods.ansiblemanager import Ansible, PLAYBOOKS, CONFIG_FILE from ansiblemethods.helper import ansible_is_valid_response ansible = Ansible() def send_email(host, port, sender, recipients, subject, body, user, passwd, use_ssl, attachemnts): """ Send an email. """ args = "host=%s \ port=%s \ sender=%s \ recipients=%s \ subject=\"%s\" \ body=\"%s\" \ user=%s \ passwd=%s \
sys.path.append ("/usr/share/alienvault-center/av-libs/avconfig") from avconfig import netinterfaces from ansiblemethods.helper import read_file from ansiblemethods.system.network import get_iface_list, \ get_iface_stats, \ get_conf_network_interfaces, \ set_interfaces_roles from ansiblemethods.server.logger import delete_raw_logs from ansiblemethods.sensor.network import get_sensor_interfaces, \ set_sensor_interfaces from ansiblemethods.ansiblemanager import Ansible AMGR = Ansible() class TestAnsibleMgr (TestCase): """ Root test class for several Ansible methods """ _multiprocess_can_split_ = False # No, I can't split the tests # because each test modified de conf of the system @classmethod def setUpClass(cls): # pylint: disable-msg=C0103 cls.__tempdir = mkdtemp(prefix="nose.temp", dir="/tmp") cls.__confpath = os.path.join( os.path.dirname( os.path.abspath( inspect.getfile(inspect.currentframe()))), "conf")
import traceback import re import time import os.path import api_log import uuid from base64 import b64decode from os.path import basename from apiexceptions.ansible import APIAnsibleError, APIAnsibleBadResponse from ansiblemethods.ansiblemanager import Ansible, PLAYBOOKS from ansiblemethods.helper import (parse_av_config_response, read_file, ansible_is_valid_response, ansible_is_valid_playbook_response, copy_file, remove_file) ansible = Ansible() def get_system_id(system_ip): """ Returns the system Id from a given ip @param system_ip: the host system ip """ host_list = [] host_list.append(system_ip) uuid_regex = re.compile( '^[a-fA-F0-9]{8}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{12}$' ) # 1- Try alienvault-system-id response = ansible.run_module([system_ip], "command", "/usr/bin/alienvault-system-id")