<commit_before>package cmd

import (
	"encoding/json"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/storage"
	"github.com/dimitertodorov/nsg-parser/parser"
	log "github.com/sirupsen/logrus"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
	"io/ioutil"
	"time"
)

//Useful command for testing your arcsight endpoint.
var testSendCmd = &cobra.Command{
	Use:   "test_send",
	Short: "Test Sending events to Syslog.",
	Run: func(cmd *cobra.Command, args []string) {
		initClient()
		initSyslog()
		logs := []byte(`[{
    "CefVersion": 0,
    "DeviceVendor": "Microsoft",
    "DeviceProduct": "Azure NSG",
    "DeviceVersion": "1",
    "DeviceEventClassId": "nsg-flow",
    "Time": "2017-06-21T15:58:09.8052328-04:00",
    "Name": "nsg-flow",
    "Severity": 0,
    "Extension": {
        "cs1": "UserRule_HTTP",
        "deviceDirection": "0",
        "dmac": "00:0D:3A:F3:38:54",
        "dpt": "80",
        "dst": "10.44.160.4",
        "outcome": "Allow",
        "proto": "TCP",
        "spt": "15425",
        "src": "10.22.1.8"
    }}]`)
		events := []parser.CefEvent{}
		err := json.Unmarshal(logs, &events)
		if err != nil {
			log.Fatal(err)
		}

		for _, flowLog := range events {
			syslogClient.SendEvent(flowLog)
		}
	},
}

var testRangeCmd = &cobra.Command{
	Use:   "test_range",
	Short: "Test Getting Range",
	Run: func(cmd *cobra.Command, args []string) {
		initClient()
		initSyslog()
		//bname := "resourceId=/SUBSCRIPTIONS/A8BB5151-C23C-4C2A-8043-B58C190C97A6/RESOURCEGROUPS/SDCCDEV01RGP01/PROVIDERS/MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/SDCCDEV01EMCOL01-NSG/y=2017/m=06/d=20/h=11/m=00/PT1H.json"
		log.Info(nsgAzureClient)
		beginTime := viper.GetString("begin_time")
		afterTime, _ := time.Parse(timeLayout, fmt.Sprintf("%s-00-00-GMT", beginTime))
		blobs, _, _ := nsgAzureClient.LoadUnprocessedBlobs(afterTime)
		//blobLength := len(*blobs)
		for _, b := range *blobs {
			getBlobRange(&b)
		}
	},
}

func getBlobRange(b *parser.NsgLogFile) {
	log.WithFields(log.Fields{
		"name": b.Blob.Name,
		"len":  b.Blob.Properties.ContentLength,
	}).Info("GOT IT")
	bOptions := storage.GetBlobRangeOptions{
		Range: &storage.BlobRange{uint64(208404), uint64(b.Blob.Properties.ContentLength)},
	}
	readCloser, err := b.Blob.GetRange(&bOptions)
	if err != nil {
		log.Fatalf("get blob range failed: %v", err)
	}
	defer readCloser.Close()
	bytesRead, err := ioutil.ReadAll(readCloser)
	log.Infof("----------------------------------------------------")
	formattedResults := fmt.Sprintf("{\"records\": [{ %s", string(bytesRead[:]))
	log.Info(formattedResults)
	nsgLog := parser.NsgLog{}
	err = json.Unmarshal([]byte(formattedResults), &nsgLog)
	if err != nil {
		log.Errorf("json parse body failed: %v - %v", err, b.Blob.Name)
	}
	b.NsgLog = &nsgLog
	log.Info(b.NsgLog)
}

func init() {
	processCmd.AddCommand(testRangeCmd)
	processCmd.AddCommand(testSendCmd)
}<commit_msg>remove unneccessary test commands<commit_after>package cmd

import (
	"encoding/json"
	"github.com/dimitertodorov/nsg-parser/parser"
	log "github.com/sirupsen/logrus"
	"github.com/spf13/cobra"
)

//Useful command for testing your arcsight endpoint.
var testSendCmd = &cobra.Command{
	Use:   "test_send",
	Short: "Test Sending events to Syslog.",
	Run: func(cmd *cobra.Command, args []string) {
		initClient()
		initSyslog()
		logs := []byte(`[{
    "CefVersion": 0,
    "DeviceVendor": "Microsoft",
    "DeviceProduct": "Azure NSG",
    "DeviceVersion": "1",
    "DeviceEventClassId": "nsg-flow",
    "Time": "2017-06-21T15:58:09.8052328-04:00",
    "Name": "nsg-flow",
    "Severity": 0,
    "Extension": {
        "cs1": "UserRule_HTTP",
        "deviceDirection": "0",
        "dmac": "00:0D:3A:F3:38:54",
        "dpt": "80",
        "dst": "10.44.160.4",
        "outcome": "Allow",
        "proto": "TCP",
        "spt": "15425",
        "src": "10.22.1.8"
    }}]`)
		events := []parser.CefEvent{}
		err := json.Unmarshal(logs, &events)
		if err != nil {
			log.Fatal(err)
		}

		for _, flowLog := range events {
			syslogClient.SendEvent(flowLog)
		}
	},
}

func init() {
	processCmd.AddCommand(testSendCmd)
}
{'fraction_non_alphanumeric': 0.1923828125, 'fraction_numerical': 0.04443359375, 'mean_word_length': 3.4581066376496192, 'pattern_counts': {'":': 39, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '3472411', 'n_tokens_mistral': 1763, 'n_tokens_neox': 1616, 'n_words': 276}