<commit_before>'use strict';

/* eslint-env node, es6 */

const child = require('child_process');
const fs = require('fs');
const http = require('http');
const path = require('path');
const url = require('url');

const chalk = require('chalk');

const cosi = require(path.resolve(path.join(__dirname, '..', '..', '..', 'cosi')));
const Plugin = require(path.resolve(path.join(cosi.lib_dir, 'plugins')));
const TemplateFetcher = require(path.resolve(path.join(cosi.lib_dir, 'template', 'fetch')));
const Metrics = require(path.join(cosi.lib_dir, 'metrics'));

/* Note:

The cassandra plugin is capable of using protocol_observer to track wire latency metrics
pertaining to cassandra. protocol_obserer is not included/installed as part of NAD or COSI.
It must be supplied locally. Example install for CentOS:

```
# install go (if needed)
curl "https://storage.googleapis.com/golang/go1.7.1.linux-amd64.tar.gz" -O
tar -C /usr/local -xzf go1.7.1.linux-amd64.tar.gz
export PATH="$PATH:/usr/local/go/bin"

# setup go environment (if needed)
mkdir godev && cd godev && mkdir bin pkg src
export GOPATH=$(pwd)

# install required headers and libs for wirelatency
yum install -y libpcap-devel

# get the wirelatency source (and dependencies)
go get github.com/circonus-labs/wirelatency

# build
cd $GOPATH/src/github.com/circonus-labs/wirelatency/protocol_observer
go build

# copy resulting protocol_observer binary somewhere in $PATH so the plugin can find it
# or to the default location of /opt/circonus/bin/protocol_observer
cp protocol_observer /opt/circonus/bin

Note that if you run NAD with dropped permissions, you will need to ensure that the user
you drop NAD to has sudo access to protocol_observer.  This is required because protocol_observer
uses libpcap to capture packets and observe the protocol.
```

*/
class Cassandra extends Plugin {

    constructor(options) {
        super(options);
        this.name = 'cassandra';
        this.instance = 'cassandra';
        this.dashboardPrefix = 'cassandranode';
        this.graphPrefix = [ 'cassandra_', 'cassandra_protocol_observer' ];
        this.enableClusters = false;
        this.logFile = path.resolve(path.join(cosi.log_dir, `plugin-${this.name}.log`));
        this.cfgFile = path.resolve(path.join(cosi.etc_dir, `plugin-${this.name}.json`));
        this.iface = optinos.iface || 'auto';
    }


    enablePlugin(cb) {
        console.log(chalk.blue(this.marker));
        console.log('Enabling agent plugin for Cassandra database');

        if (this._fileExists(this.cfgFile) && !this.options.force) {
            console.log(chalk.green('\tPlugin scripts already enabled'), 'use --force to overwrite NAD plugin script config(s).');
            cb(null);
            return;
        }

        let err = null;

        err = this._test_nodetool();
        if (err === null) {
            console.log(chalk.green('\tPassed'), 'nodetool test');
            err = this._create_observer_conf();
        }
        if (err !== null) {
            cb(err);
            return;
        }
        console.log(chalk.green('\tCreated'), 'protocol_observer config');

        this.activatePluginScripts(cb);<commit_msg>fix: typo, it is "options"...<commit_after>'use strict';

/* eslint-env node, es6 */

const child = require('child_process');
const fs = require('fs');
const http = require('http');
const path = require('path');
const url = require('url');

const chalk = require('chalk');

const cosi = require(path.resolve(path.join(__dirname, '..', '..', '..', 'cosi')));
const Plugin = require(path.resolve(path.join(cosi.lib_dir, 'plugins')));
const TemplateFetcher = require(path.resolve(path.join(cosi.lib_dir, 'template', 'fetch')));
const Metrics = require(path.join(cosi.lib_dir, 'metrics'));

/* Note:

The cassandra plugin is capable of using protocol_observer to track wire latency metrics
pertaining to cassandra. protocol_obserer is not included/installed as part of NAD or COSI.
It must be supplied locally. Example install for CentOS:

```
# install go (if needed)
curl "https://storage.googleapis.com/golang/go1.7.1.linux-amd64.tar.gz" -O
tar -C /usr/local -xzf go1.7.1.linux-amd64.tar.gz
export PATH="$PATH:/usr/local/go/bin"

# setup go environment (if needed)
mkdir godev && cd godev && mkdir bin pkg src
export GOPATH=$(pwd)

# install required headers and libs for wirelatency
yum install -y libpcap-devel

# get the wirelatency source (and dependencies)
go get github.com/circonus-labs/wirelatency

# build
cd $GOPATH/src/github.com/circonus-labs/wirelatency/protocol_observer
go build

# copy resulting protocol_observer binary somewhere in $PATH so the plugin can find it
# or to the default location of /opt/circonus/bin/protocol_observer
cp protocol_observer /opt/circonus/bin

Note that if you run NAD with dropped permissions, you will need to ensure that the user
you drop NAD to has sudo access to protocol_observer.  This is required because protocol_observer
uses libpcap to capture packets and observe the protocol.
```

*/
class Cassandra extends Plugin {

    constructor(options) {
        super(options);
        this.name = 'cassandra';
        this.instance = 'cassandra';
        this.dashboardPrefix = 'cassandranode';
        this.graphPrefix = [ 'cassandra_', 'cassandra_protocol_observer' ];
        this.enableClusters = false;
        this.logFile = path.resolve(path.join(cosi.log_dir, `plugin-${this.name}.log`));
        this.cfgFile = path.resolve(path.join(cosi.etc_dir, `plugin-${this.name}.json`));
        this.iface = options.iface || 'auto';
    }


    enablePlugin(cb) {
        console.log(chalk.blue(this.marker));
        console.log('Enabling agent plugin for Cassandra database');

        if (this._fileExists(this.cfgFile) && !this.options.force) {
            console.log(chalk.green('\tPlugin scripts already enabled'), 'use --force to overwrite NAD plugin script config(s).');
            cb(null);
            return;
        }

        let err = null;

        err = this._test_nodetool();
        if (err === null) {
            console.log(chalk.green('\tPassed'), 'nodetool test');
            err = this._create_observer_conf();
        }
        if (err !== null) {
            cb(err);
            return;
        }
        console.log(chalk.green('\tCreated'), 'protocol_observer config');

        this.activatePluginScripts(cb);
{'fraction_non_alphanumeric': 0.12955402010050251, 'fraction_numerical': 0.003454773869346734, 'mean_word_length': 3.3743131868131866, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4882772', 'n_tokens_mistral': 2012, 'n_tokens_neox': 1932, 'n_words': 535}