Cheat Sheet

 

 

 

 

 

 

BitBucket

re-order CI

Add in comment:
test this please

Downloads

Development ova

link

 

GA ova

link

 

Knowledge package - develop

 

 

Knowledge package - GA

 

Installation

Virtual server

link

 

Migrating from Ubuntu 14.04 to Ubuntu 18.04

link

 

Knowledge package

 

 

Server commands

imanage
imanage setup

imanage magic (for knowledge)
ik-0.0.0.develop
ik-7.2.0.671

 

Development

GIT

Self explanatory:

  • git status

  • git checkout <branch name>

 

Other

  • git fetch
    git fetch is the command that tells your local git to retrieve the latest meta-data info from the original (yet doesn't do any file transferring. It's more like just checking to see if there are any changes available). 

  • git pull
    git pull on the other hand does that AND brings (copy) those changes from the remote repository.

  • git push
    Push code to repository

  • git push origin --delete <version>
    Delete remote branch

  • git branch

    • git branch: lists local branches

    • git branch -a: lists local and remote branches

    • git branch -d <branch_name>: delete local branch (use -D for force)

  • git diff --staged

  • git diff-tree --no-commit-id --name-only -r <commit_id>
    Committed file names only

  • git rm --cached <filename>

  • git mv <old name> <new name>

  • git log
    Viewing the Commit History

  • git show <commit_id>
    View commit diff

Compare 2 branches

  • One line per commit
    git log remotes/origin/release/v7.1.0..remotes/origin/release/v7.2.0 --pretty=oneline

  • Full comments
    git log remotes/origin/release/v7.1.0..remotes/origin/release/v7.2.0

How to “sync” locally:

  • Suppose you make a new branch (new_branch) deriving from branch “base_branch”

  • You do your work and make some commits to new_branch.

  • Meanwhile, others have merged changes into base_branch

  • When it comes time to merge new_branch into base_branch you need to Sync.

  • To sync new_branch with base_branch:

    • checkout base_branch and run git pull

    • checkout new_branch and run git merge base_branch

    • Resolve any conflicts that appear, add all relevant files with git add then git commit

    • Your branch is now synced with base_branch and you can make a PR with confidence that the CI will succeed (or at least not fail due to conflicts)

Fixing conflicts:
From CLI, run the following, based on this link:

  • Enter into your repository: cd ~/<repo_directory>

  • Pull the latest version into your local rep: git pull

  • Checkout into your feature branch (the branch which include the fix you wanted to merge): git checkout <feature_branch>

  • Attempt to merge the files locally, in order to trigger a failure: git pull origin <destination_branch>

  • You will receive a list of files which has conflicts. You have the options:
    Either edit each file (using pycharm for example), and determine what should be the correct version.
    Use the tool from pycharm: VCS → Git → “Resolve Conflicts”, then, you can choose the correct version.

  • Once done, proceed to merge your code again:
    $ git add <filename> $ git commit -m'commit message'

  • Push your change using your branch name: git push origin <feature_branch>

Server

 

Restart automation services
sudo service indeni-automation status

Configuration file
/usr/share/indeni/conf/application.conf

Jenkins

 

Building feature branch

If you would like to create a new private build for testing, enter this section in Jenkins:
build → build_knowledge

Click on: “Build with Parameters”, and place your parameters, with your feature branch, and click “Build”.
Example:

 

Building complete indeni package
Indeni → Development → indeni-0.0.0

 

 

Install server indeni-workflow package

  • pip3 uninstall indeni-workflow

  • pip3 install "indeni_workflow==0.0.0.*" --extra-index-url https://indeni.jfrog.io/indeni/api/pypi/indeni-pypi-develop/simple

Install server indeni-parser package

  • pip3 uninstall indeni-parser

  • pip3 install "indeni_parser==0.0.0.*" --extra-index-url https://indeni.jfrog.io/indeni/api/pypi/indeni-pypi-develop/simple

Parsing

RegEx

https://www.rexegg.com/regex-quickstart.html

 

TextFSM

Introduction

https://github.com/google/textfsm/wiki/Code-Lab

Database

PostgreSQL

Delete issue
delete from alert where id='<issue_id>';

delete from alert where id='17fd8ee7-2ec2-4f98-ace6-f1236846f3d7';

psql -c "delete from alert where id='e60904dc-fdcc-4231-b357-cb3a40c29b53'";

Show tables
\dt

Show scehma of a table
\d+ <table_name>

Find device info
psql -c "select id, ip_address, name from device;"

 

MongoDB

Query the in-memory db using a REST API call

Get device ID:

curl -G -k -u "<user>:<pwrd>" https://localhost:9009/api/v1/devices/<your-device-id>

curl -G -k -u "indeni:indeni123" https://localhost:9009/api/v1/devices/9b2fd07d-6373-4610-a2c4-7247945f97ba

Get metric:

curl -G -k -u "admin:admin123!" "https://localhost:9009/api/v1/metrics" --data-urlencode "query=(im.name==<metric_name> and device-id=='<device_id>')" | python -m json.tool

curl -G -k -u "admin:admin123!" "https://localhost:9009/api/v1/metrics" --data-urlencode "query=(im.name==config-unsaved and device-id=='f8dccd39-fc7f-4e41-aa03-81965c9c9fde')" | python -m json.tool

 

MySQL

SHOW FULL TABLES;
SHOW TABLES;
SHOW TABLES LIKE 'alert';
SHOW databases;
SELECT * FROM alert;
SELECT [*] FROM [TableName] WHERE [condition1] [AND [OR]] [condition2]...

SELECT column_name()
FROM table_name
ORDER BY column_name() ASC or DESC

 

JSON parser

https://jsoneditoronline.org/#left=cloud.76693f427cd04399963c3e412ac4af

XML API

API explore

How to explore PAN API

PAN Retrieve API Key

curl -k -X GET 'https://<firewall>/api/?type=keygen&user=<username>&password=<password>'

Example
curl -k -X GET 'https://10.11.95.31/api/?type=keygen&user=indeni&password=indeni123'

PAN API call

https://<device_ip>/api/?type=op&cmd=<command>&key=<api_key>

Example
curl -k '<https://10.11.95.31/api/?type=op&cmd=<show><config><synced-diff></synced-diff></config></show>&key=LUFRPT1KcXQ4bmlkMDh6Vk5QU2pHMUgyVVlwajRBTWM9czdNTk5SeENtK0N3VFF4SEloWFFzTXVTdHRyYVNtMUdoOUE5U3JiSi9EQklCd1Y1ZHp1M2t2TzRybWlvdm9xRg=='>

BASH

Environment variables

IKBUILD=/usr/share/indeni-knowledge/stable/ind/meta/knowledge-version.properties
IKPARSERS=/usr/share/indeni-knowledge/stable/ind/parsers
IKWORKFLOWS=/usr/share/indeni-knowledge/stable/automation/workflows
IKRULES=/usr/share/indeni-knowledge/stable/rules
IKLOG=/usr/share/indeni/logs/rules/
IS_SERVICES=/usr/share/indeni-services


IK_KNOWLEDGE_CATALOG=/usr/share/indeni-services/logs/knowledge-catalog.log
IS_DEVICE_LOG=/usr/share/indeni-collector/logs/devices/<device_ip>.log
IS_COLLECTOR_LOG=/usr/share/indeni-collector/logs/collector.log
IS_PARSER_LOG=/usr/share/indeni-services/logs/parser.log
IS_GENERAL=/usr/share/indeni/logs/rules/general.log

 

 

echo 'one two three' | xargs cat

Command Runner

 

Parse only
command-runner parse-only <IND path> -f <input file>

Full command
command-runner full-command <IND path> <device IP> --ssh indeni,indeni123 --api-key LUFRPT1WdnZtQndJdG5COUc2US9mMXF6ZjJjOTdlOWM9czdNTk5SeENtK0N3VFF4SEloWFFzRlAydlVpamFudTlDTXk4OGEyQjYwc2hFSnNVa3lVN3NqQm1yRmtORjJPcQ==

Compile only
command-runner compile-only <IND path>

Test

command-runner test create <IND path> <test name> <input file>

 

 

Rule Runner

 

s3://indeni-public/packages/tools/devtools/rule-runner-latest.zip

Docker

 

sudo docker ps
sudo docker logs -f <container name>

UI

 

Metric explorer

Parser Testing

Python

Add the following lines to the end of the parser script to get the input data from the file and check the parser operation:
FILE_PATH_RAW_DATA = "test_file_path" f = open(FILE_PATH_RAW_DATA, "r") raw_data = f.read() f.close() helper_methods.print_list(ClassName().parse(raw_data, {}, {}))