Пример #1
0
def check_splunk():    
    setup_django_environment()
    
    from django.conf import settings
    from splunklib.client import Service
    
    host = settings.SPLUNKD_HOST
    port = settings.SPLUNKD_PORT
    service = Service(
        token="unnecessary_token",
        host=host,
        port=port
    )
    
    version = [0]
    try:   
        info = service.info()
        version = map(int, info.version.split("."))
    except Exception as e:
        print "Could not connect to Splunk at %s:%s" % (host, port)
        sys.exit(1)
        
    # Make sure it is greater than Splunk 5.0, or an internal build
    if (version[0] < 5 and not version[0] > 1000):
        print "You have Splunk %s, but Splunk AppFx requires Splunk 5.0 or later" % info.version
        sys.exit(1)
Пример #2
0
def check_splunk():    
    setup_django_environment()
    
    from django.conf import settings
    from splunklib.client import Service
    
    host = settings.SPLUNKD_HOST
    port = settings.SPLUNKD_PORT
    scheme = settings.SPLUNKD_SCHEME
    
    service = Service(
        token="unnecessary_token",
        scheme=scheme,
        host=host,
        port=port
    )
    
    version = [0]
    try:   
        info = service.info()
        version = map(int, info.version.split("."))
    except Exception as e:
        print "Could not connect to Splunk at %s:%s." % (host, port)
        sys.exit(1)
        
    # Make sure it is greater than Splunk 5.0, or an internal build
    if (version[0] < 5 and not version[0] > 1000):
        print "You have Splunk %s, but the Splunk Application Framework requires Splunk 5.0 or later." % info.version
        sys.exit(1)
Пример #3
0
class ConfigApp(admin.MConfigHandler):
    """
    Set up supported arguments
    """

    def __init__(self, *args, **kwargs):
        super(ConfigApp, self).__init__(*args, **kwargs)

        self.service = Service(scheme="https", host="localhost", port=8089, app=APP_NAME, token=self.getSessionKey())

    def setup(self):
        if self.requestedAction == admin.ACTION_EDIT:
            for arg in ["access_token", "signalfx_realm", "ingest_url", "ssl_verify"]:
                self.supportedArgs.addOptArg(arg)

    def handleList(self, conf_info):  # pylint:disable=invalid-name
        """
        Read the initial values of the parameters from the custom file
        sfx.conf, and write them to the setup page.

        If the app has never been set up,
        uses .../signalfx-forwarder/default/sfx.conf.

        If app has been set up, looks at
        .../local/sfx.conf first, then looks at
        .../default/sfx.conf only if there is no value for a field in
        .../local/sfx.conf

        For boolean fields, may need to switch the true/false setting.
        For text fields, if the conf file says None or empty string,
        set to the empty string.
        """
        conf_dict = self.readConf("sfx")
        if conf_dict is not None:
            for stanza, settings in conf_dict.items():
                for key, val in settings.items():
                    conf_info[stanza].append(key, val or "")

        access_token = get_access_token(self.service)
        conf_info["setupentity"].append("access_token", access_token)

    def handleEdit(self, _):  # pylint:disable=invalid-name
        """
        After user clicks Save on setup page, take updated parameters,
        normalize them, and save them somewhere
        """
        data = {k: [s or "" for s in v] for k, v in self.callerArgs.data.items()}

        server_info = self.service.info()
        if server_info.get("instance_type") == "cloud":
            ingest_url = data.get("ingest_url")
            if ingest_url and ingest_url[0] and not ingest_url[0].startswith("https"):
                raise admin.ArgValidationException("ingest_url must be https in Splunk Cloud")

        access_token_list = data.pop("access_token")
        if not access_token_list:
            raise admin.ArgValidationException("required access token is missing")
        self.save_access_token(access_token_list[0])
		
		ssl_verify = data.pop("ssl_verify")

        # Since we are using a conf file to store parameters,
        # write them to the [SignalFxConfig] stanza
        # in splunk-forwarder/local/sfx.conf
        self.writeConf("sfx", "setupentity", data)