CyberKeeda In Social Media

How to Use Sumologic API

Sumo Logic

If you are new to sumo, it's a kind of log aggregating tool that can be used further for data representational, monitoring, analytics and many more, Splunk is an industrial well know application within the same industry and market as a competitor.

Sumo Logic API

Apart from a very interactive GUI, Sumo Logic exposes APIs to access resources and log data from third-party scripts and applications, and also to configure Sources via JSON.


How to use.

Authentication :  Sumo Logic provides two methods of authentication
  1. Access Id and Access Key
  2. Base64 encoded accessid and access key
In this post, we will cover point 1, that is authentication using accessid and accesskey.
First, let's generate a pair of accessid and accesskey.

Login to your sumo logic account --> Expand the left navbar --> scroll down to bottom click to expand on your account name --> Preferences --> Add Access Key --> Generate and Save.




Now you are ready with the AccessID and Accesskey, we will move to test authentication using credentials.

Before we proceed, you must know API endpoints of your as this will be used further.
So we have our access credentials ready and we know our api endpoint, below one liner can be used to authenticate Sumo Logic API endpoints.

Do replace your Accessid, Accesskey and API endpoints by yours one, don't worry if you get a 404 response it's expected.

curl -u "<accessId>:<accessKey>" -X GET <API Endpoint>

Expected response :  <title>Error 404 Not Found</title>


Sumo Logic Search JOB API

The search job API provides third part scripts and applications access to your log data after using mandatory above authentication, it can be used further as per requirement.

Mandatory Requirements 

  • If you are familiar with searches in sumo, you must be aware that some complex and large time drift queries takes more time then usual, keeping in mind this scenario once a search job request is initiated, it must be keep alive/running by polling for status of the provided job id upon submitting search job request. If not done so, a search job is cancelled after five minutes of inactivity.
  • You must enable cookies for subsequent request to Search Job API.
  • Access ID and Access Secret.
  • Valid API endpoint.
  • Valid Search String in JSON format.


Creating a Search Job using API.
Create a empty JSON document/file and paste the below content and replace it by your own data.

{
          "query": "| _collector=my_prod_collect_01| count",
          "from": "2019-07-28T12:00:00",
          "to": "2019-07-28T13:10:00",
          "timeZone": "GMT"
}

Query ( type : String ) -- Replace it by your own SumoLogic search query.
From ( type: String )   -- Replace if by yours with format like YYYY-MM-DDTHH:mm:ss
To ( type: String )         -- Replace if by yours with format like YYYY-MM-DDTHH:mm:ss
TimeZone ( type: String )  -- Replace if by yours with timezone (ie : GMT,PST,DST) etc 

Create  One liner to submit search to grab search id.
curl -b cookies.txt -c cookies.txt -H 'Content-type: application/json'  -H 'Accept: application/json' -X POST -T mytest.json  --user "ACESSID:ACCESSKEY"  https://api.us2.sumologic.com/api/v1/search/jobs 

Expected response

{
  "id": "1EE8BFBCD715",
  "link": {
    "rel": "self",
    "href":"https://api.us2.sumologic.com/api/v1/search/jobs/1EE8BFBCD715"
  }
}

Where "1EE8BFBCD715""is your search job id, that could be used to find search job result using below one liner.


curl -b cookies.txt -c cookies.txt -H 'Accept: application/json' --user ACESSID:ACCESSKEY https://api.us2.sumologic.com/api/v1/search/jobs/1EE8BFBCD715

Expected Response.

{
  "state": "DONE GATHERING RESULTS",
  "histogramBuckets": [
    {
      "startTimestamp": 1567663200000,
      "length": 3600000,
      "count": 7380
    },

Try to post your queries, will try to help you with errors.


Read more ...

How to export and import Jenkins job.

If you have multiple jenkins instances, there might be a requirement to export an existing jenkins job, that could be further imported into the newer jenkins instance.

We will learn how to do the export/import of jenkins job using jenkins cli.

How to Export existing Jenkins job.

  • Jenkins Home Page 
  • Manage Jenkins
  • Jenkins CLI.
  • Download  jenkins-cli.jar


  • Click on Jenkins CLI.




Once file "jenkins-cli.jar" file has been downloaded, we are ready to export our Jenkins job, lets do it.
Open your terminal and run the below commands.

Authenticate and List down your jobs to identify the one, which one you want to export, replace "your-jenkins-server-url:your_server_port" from your source jenkins server's url and port.

cyberkeeda@jenkins-master:~$ java -jar jenkins-cli.jar -s "http://your-jenkins-server-url:your_server_port" -auth UserName:Password  list-jobs

djpass-ansible
djpass-docker-app
docker ps

Now, from above enlisted jobs i want to export the one named as "djpass-docker-app".
Run the below command and replace the highlighted one by yours.

cyberkeeda@jenkins-master:~$  java -jar jenkins-cli.jar -s "http://your-jenkins-server-url:your_server_port" -auth UserName:Password get-job djpass-docker-app > djpass-docker-app.xml

We have successfully exported our jenkins job named as "djpass-docker-app" as an xml file named as "djpass-docker-app.xml"

How to import Jenkins job to different Jenkins server.

  • Go to your new jenkins server dashboard, where you want to import.
  • Follow the same above steps to download the jenkins-cli.jar file.
  • Ensure you are ready with "jenkins-cli.jar" and your exported jenkins job XML file with you.
Now run the below command to import your jenkins job xml file to new jenkins server.
Note : Replace the highlighted one by yours.

Preview:
cyberkeeda@jenkins-slave:~$  java -jar jenkins-cli.jar -s "http://your-Newjenkins-server-url:your_server_port" -auth UserName:Password create-job new-djpass-docker-app < djpass-docker-app.xml

Hoah !!! Thats it, check your dashboard to verify the same.

Read more ...

How to install latest version of docker-compose on Ubuntu 18.04



Docker Compose requirements:

  • Pre-installed docker engine.


One liner command to install docker compose.

$  sudo curl -L https://github.com/docker/compose/releases/download/1.24.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

    Verify the installation by checking installed docker compose version.

    $  docker-compose --version
       
      Do let me know your installed version in comments, mine is 

      docker-compose version 1.24.0, build 0aa59064

      Read more ...

      How to install Jenkins on Ubuntu 18.04 Bionic


      Here we go, proceed with the below steps.


      • Mandatory requirement : Jave aka OpenJDK.
      $  sudo apt install openjdk-8-jdk
      Once installed verify the installation using the below command.
      $  java -version

      • Installing Jenkins.

      Official Ubuntu ships with older versions of jenkins, why lag behind let's add the new sources to install the latest version.

      • Add repository key first.
      $  wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
      • Once you got an OK confirmation, let's proceed to add debian package repository address to the our server's source list.
      $  sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
      • Now we are almost ready to install jenkins, lets make an update now
      $  wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
      • Here we go, install jenins now
      $  sudo apt install jenkins

      • Start Jenkins

      $  sudo systemctl start jenkins

        Access Admin Password to login to Jenkins UI.
        Open CLI, hit below cat command and grab the initial login password.

        $  sudo cat /var/lib/jenkins/secrets/initialAdminPassword

        Login to UI.

        $  http://<Your Jenkins Server IP>:8080/

          Further steps are self explanatory, install suggested plugins and change the initial admin password with your. 







          Read more ...

          Ubuntu Fix : Could not open lock file /var/lib/dpkg/lock-frontend - open (2: No such file or directory)


          Full Error :

          E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
          E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?

          Fix :

          $ ps aux | grep -i apt
          : Find the corresponding PIDs, Kill using ( kill -9 <PID> and check if error went.

          An alternate for the above is to run below command.

          sudo killall apt apt-get
          
          Read more ...

          How to install and configure Docker-CE on CentOS



          Installation.

          • Begin with updating your system packages and docker dependencies.
          $  sudo yum update
          $  sudo yum install yum-utils device-mapper-persistent-data lvm2
          • Add docker stable repository for centos within your system
          $  sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
          • Once docker repository is enabled, proceed ahead to install Docker-CE ( Community Edition.
          $  sudo yum install docker-ce
          • Now docker-ce has been installed, lets start the docker daemon and enable it on boot.
          $  sudo systemctl start docker
          $  sudo systemctl enable docker
          • To verify the status of  docker, run the below command.
          $  sudo systemctl status docker











          • In case, if you want to check your installed docker version.
          $  sudo docker -v

          Run Docker commands without sudo

          By default managing Docker requires administrator privileges. If you want to run Docker commands as a non-root user without adding sudo within yoir command you need to add your user to the docker group which is created during the installation of the Docker CE package. Add your user to docker group by below command.

          $  sudo usermod -aG docker $USER

          Logout- Login to reflect the changes.
          Read more ...
          Related Posts Plugin for WordPress, Blogger...
          Designed By Kunal Saha