func printMessageActionObtain(options Options) {
	log.Printf("Checking conditions for do action '%s' in papertrail params: "+
		"[--group-name %s] [--system-wildcard %s] [--search %s] [--query %s] "+
		"[--start-date %s] [--end-date %s] [--path %s]\n",
		options.Action, options.GroupName, options.SystemWildcard, options.Search,
		options.Query, options.StartDate, options.EndDate, options.Path)
}
printMessageActionObtain prints the possible message when the action to perform is obtain
package papertrail
import (
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"net/http"
	"os"
	"regexp"
	"strconv"
)
func CheckValidActionsConditions(action string) error {
	validActions := []string{"c", "create", "o", "obtain", "d", "delete"}
	_, found := find(validActions, action)
	if !found {
		return errors.New("Not valid option provided for action to perform, the only valid values are: \n" +
			"\t'c' or 'create': create new system/s, group and/or search\n" +
			"\t'd' or 'delete': create new system/s, group and/or search\n" +
			"\t'o'or 'obtain': obtain logs in base of parameters provided\n")
	}
	return nil
}
func checkStDateEndDateFmt(startDate string, endDate string) error {
	err := CheckDateFormat(startDate)
	if err != nil {
		return fmt.Errorf("cannot parse startdate: %v", err)
	}
	err = CheckDateFormat(endDate)
	if err != nil {
		return fmt.Errorf("cannot parse enddate: %v", err)
	}
	return nil
}
func cnvStDateEndDateToUnixTime(startDate string, endDate string) (int64, int64, error) {
	err := checkStDateEndDateFmt(startDate, endDate)
	if err != nil {
		return 0, 0, err
	}
	startDateUnix, err := GetTimeStampUnixFromDate(startDate)
	if err != nil {
		return 0, 0, err
	}
	endDateUnix, err := GetTimeStampUnixFromDate(endDate)
	if err != nil {
		return 0, 0, err
	}
	return startDateUnix, endDateUnix, nil
}
func checkNecessaryConditions(action string, systemType string, ipAddress string,
	destinationId int, destinationPort int, startDate int64, endDate int64) error {
	papertrailToken := os.Getenv("PAPERTRAIL_API_TOKEN")
	if len(papertrailToken) == 0 {
		return errors.New("Error getting value of PAPERTRAIL_API_TOKEN, " +
			"it's necessary to define this variable with your papertrail's API token ")
	}
	err := CheckValidActionsConditions(action)
	if err != nil {
		return err
	}
	err = checkValidSystemTypeConditions(systemType, ipAddress, destinationId, destinationPort, action)
	if err != nil {
		return err
	}
	if startDate > endDate {
		return fmt.Errorf("startdate > enddate - please set proper data boundaries")
	}
	return nil
}
func apiOperation(method string, url string, bodyToSend io.Reader) (*ApiResponse, error) {
	req, err := http.NewRequest(method, url, bodyToSend)
	if err != nil {
		return nil, err
	}
	req.Header.Add(papertrailTokenName, os.Getenv("PAPERTRAIL_API_TOKEN"))
	req.Header.Add("Content-Type", "application/json")
	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}
	return &ApiResponse{
		Body:       body,
		StatusCode: resp.StatusCode,
		err:        err,
	}, nil
}
func systemTypeIsHostname(systemType string) bool {
	if systemType == "h" || systemType == "hostname" {
		return true
	}
	return false
}
func systemTypeIsIpAddress(systemType string) bool {
	if systemType == "i" || systemType == "ip-address" {
		return true
	}
	return false
}
func checkValidSystemTypeConditions(systemType string, ipAddress string, destinationId int,
	destinationPort int, actionType string) error {
	validSystemTypes := []string{"h", "hostname", "i", "ip-address"}
	_, found := find(validSystemTypes, systemType)
	if !found {
		return errors.New("Not valid option provided for system, the only valid values are: \n" +
			"\t'h' or 'hostname': system based in hostname\n" +
			"\t'i'or 'ip-address': system based in ip-address\n")
	} else if !ActionIsDelete(actionType) {
		if systemTypeIsHostname(systemType) {
			if destinationId != 0 && destinationPort != 0 {
				return errors.New("If the system is a hostname-type system, only destination " +
					"id or destination port can be specified\n")
			} else if !((destinationId != 0 && destinationPort == 0) ||
				(destinationId == 0 && destinationPort != 0)) {
				return errors.New("It's necessary provide a value distinct from default (0) to " +
					"destination id or destination port ")
			}
		} else if systemTypeIsIpAddress(systemType) {
			re := regexp.MustCompile(`(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}`)
			if !re.MatchString(ipAddress) {
				return errors.New("The IP Address provided, " + ipAddress + " it's not a valid IP Address ")
			}
		}
	}
	return nil
}
func ActionIsCreate(actionOptionName string) bool {
	if actionOptionName == "c" || actionOptionName == "create" {
		return true
	}
	return false
}
func ActionIsDelete(actionOptionName string) bool {
	if actionOptionName == "d" || actionOptionName == "delete" {
		return true
	}
	return false
}
func ActionIsObtain(actionOptionName string) bool {
	if actionOptionName == "o" || actionOptionName == "obtain" {
		return true
	}
	return false
}
func getNameOfAction(actionOptionName string) string {
	if ActionIsCreate(actionOptionName) {
		return "create"
	} else if ActionIsDelete(actionOptionName) {
		return "delete"
	}
	return "obtain"
}
func find(slice []string, val string) (int, bool) {
	for i, item := range slice {
		if item == val {
			return i, true
		}
	}
	return -1, false
}
func getOnlyElementsCreatedOrRemovedDistinctEventSearch(papertrailToAddItems []Item, createdOrRemovedItems []Item) []Item {
	for _, item := range papertrailToAddItems {
		if item.Deleted || item.Created || item.ItemType == "EventsSearch" {
			createdOrRemovedItems = append(createdOrRemovedItems, item)
		}
	}
	return createdOrRemovedItems
}
func addItemsToCreatedOrDeletedItems(papertrailToAddItems []Item, papertrailItemsCreatedOrDeleted []Item) []Item {
	return getOnlyElementsCreatedOrRemovedDistinctEventSearch(papertrailToAddItems, papertrailItemsCreatedOrDeleted)
}
func addItemToCreatedOrDeletedItems(papertrailToAddItem Item, papertrailItemsCreatedOrDeleted []Item) []Item {
	var newItems []Item
	if papertrailToAddItem.Deleted || papertrailToAddItem.Created ||
		papertrailToAddItem.ItemType == "EventsSearch" {
		newItems = append(papertrailItemsCreatedOrDeleted, papertrailToAddItem)
	} else {
		return papertrailItemsCreatedOrDeleted
	}
	return newItems
}
func convertStatusCodeToError(statusCode int, resource string, action string) error {
	if statusCode == 404 {
		return errors.New("Error: " + resource + " not found ")
	}
	return errors.New("Error: " + action + " " + resource + " Status Code " + strconv.Itoa(statusCode) + " received ")
}
func checkConditionsForDeleteAllSystems(actionName string, deleteAllSystems bool) bool {
	if !ActionIsDelete(actionName) {
		return true
	} else if ActionIsDelete(actionName) && deleteAllSystems {
		return true
	}
	return false
}
func checkConditionsForSkipGroupSearch(actionName string, deleteAllSystems bool) bool {
	if ActionIsDelete(actionName) || ActionIsObtain(actionName) && deleteAllSystems {
		return true
	}
	return false
}
func printMessageActionDelete(options Options) {
	if options.DeleteOnlySystems {
		log.Printf("Checking conditions for do action '%s' in papertrail params: "+
			"[--group-name %s] [--system-wildcard %s] [--delete-all-searches %t] "+
			"[--delete-only-searches %t] [--delete-all-systems %t] [--delete-only-systems %t]\n",
			options.Action, options.GroupName, options.SystemWildcard,
			options.DeleteAllSearches, options.DeleteOnlySearches, options.DeleteAllSystems,
			options.DeleteOnlySystems)
	} else {
		log.Printf("Checking conditions for do action '%s' in papertrail params: "+
			"[--group-name %s] [--system-wildcard %s] [--search %s] [--delete-all-searches %t] "+
			"[--delete-only-searches %t] [--delete-all-systems %t] [--delete-only-systems %t]\n",
			options.Action, options.GroupName, options.SystemWildcard, options.Search,
			options.DeleteAllSearches, options.DeleteOnlySearches, options.DeleteAllSystems,
			options.DeleteOnlySystems)
	}
}
func printMessageActionCreate(options Options) {
	if options.DestinationId != 0 {
		log.Printf("Checking conditions for do action '%s' in papertrail params: "+
			"[--group-name %s] [--system-wildcard %s] [--destination-id %d] [--search %s] [--query %s]\n",
			options.Action, options.GroupName, options.SystemWildcard, options.DestinationId,
			options.Search, options.Query)
	} else if options.DestinationPort != 0 {
		log.Printf("Checking conditions for do action '%s' in papertrail params: "+
			"[--group-name %s] [--system-wildcard %s] [--destination-port %d] [--search %s] [--query %s]\n",
			options.Action, options.GroupName, options.SystemWildcard, options.DestinationPort,
			options.Search, options.Query)
	} else {
		log.Printf("Checking conditions for do action '%s' in papertrail params: "+
			"[--group-name %s] [--system-wildcard %s] [--search %s] [--query %s]\n",
			options.Action, options.GroupName, options.SystemWildcard, options.Search, options.Query)
	}
}