CyberKeeda In Social Media

An introduction to Dashing and Smashing dashboard frameworks


Dashing

The exceptionally handsome dashboard framework in Ruby and Coffeescript.

You can go through the slide to have a intro about it.




Read more ...

S3cmd - A faster way for AWS S3 Operations.


S3cmd


A very faster and reliable CLI tool for AWS object storage (S3) operations.


So this tutorial is just a walk through to
  • How to install s3cmd
  • How to configure S3cmd
  • Basic operations copy, move, list.

Requirements.
  • AWS Console access.
  • API Token for same account.
  • PIP is installed within Windows system to install python packages

Installation.

For Windows
pip install s3cmd
For Linux
sudo apt-get install s3cmd -y


Configuration.

Before we proceed to run cli commands, let configure s3cmd configuration file to authenticate.

For Linux -
Toggle to home directory of your account.

# cd ~
Create an empty hidden file named as .s3cfg

# touch .s3cfg
Add the below lines and add your own access_key and secret_key and save.

[default]

# Login credentials
access_key = AKMYOWNACCESSKEYHDEG
secret_key = 1DwMYownAccessSecretKeyoOV8

Now we are ready to do s3 operations using s3cmd cli, all cli commands are same for windows and linux operating systems.


Object Storage operations.

  • List content of your S3 Bucket.
# s3cmd ls s3://<Your AWS Bucket Name/
  • Create an new Bucket
# s3cmd mb s3://my_own_s3_newbucket/
  • Uploading content within a Bucket.
# s3cmd put myfile1.txt myimage.jpg s3://my_own_s3_newbucket/
    • Download content from Bucket.
    # s3cmd get s3://my_own_s3_newbucket/myimage.jpg myimage.jpg
    • Remove and existing Bucket
    # s3cmd rb s3://my_own_s3_newbucket/
      • Move content of one bucket(Source) to another(Destination).
      # s3cmd mv --recursive s3://failed/ s3://old_failed/



      Read more ...

      Ubuntu 18.04 Error : We cannot detect a running copy of GNOME on this system.

      You might be trying to install GNOME-Shell Extension from browser and got an error like "We cannot detect a running copy of GNOME on this system, so some parts of the interface may be disabled"

      Fix : Install GNOME Shell Integration plugin

      How to install it, lets follow the below steps.

      For Chrome :


      • Chrome Web Store --> Search for "Gnome shell integration" --> Add to Chrome
      • Open Terminal and install chrome-gnome-shell


      sudo apt-get install chrome-gnome-shell
      • Restart Browser and try to install additional Gnome extensions.














      For Firefox :
      • Firefox Add On --> Search for "Gnome shell integration" --> Add to Firefox --> Followup the instructions asked by Firefox to add it.

      • Restart Browser and try to install additional Gnome extensions.















      Read more ...

      Creating Random password generator using AWS Lambda Function


      AWS Lambda


      AWS Lambda is an serverless computing platform served by Amazon  Amazon Web Services. It is a PAAS computing service that runs code in response to events and automatically manages the computing resources required by that code.



      So this tutorial is just a walk through to
      • How to run your python code from AWS Lambda
      • How to make use of AWS lambda to create tiny python application
      • Python based random strong password generator hosted on AWS Lambda.
      • How to create AWS Lambda Function for Python

      Let's begin.
      In order to run python code from Lambda function, the first thing we do is to create a Handler within Lambda function, which will trigger the ineer python function using event and context

      A basic lambda function handler looks like the below code.

      def handler_name(event, context): 
          ...
          return some_value

      Now let's focus on the above code.

      • handler_name : type (String ) It could be anything, but there is great use of it further.
      • event : type (dictionary) It's the way through which we can feed variable to our inner python code/programme.
      • context : In simple terms it will be used for the logging and debugging purpose.
      Above things are just theory, i'm quite sure once i let you know how to run our python code using above defined parameters, you will use it then further for you.

      Lets toggle down to Lambda Service from AWS Console and create a function.

      Services --> Compute --> Lambda --> Functions --> Create Function


















      Select Author from Scratch and proceed to fill the basic information for your new lambda function and then click on create function.

      Function name : Enter a name that describes the purpose of your function, it must be anything.
      Here i will be creating a lambda function to generate random password, hence we will name it as "Password_Generator"

      Run time : Choose your desired language, we will  python 3.7 here.

      Permissions : Lambda function need appropriate IAM role to run, for now choose option "Create a new role with basic lambda permissions"

      Permissions --> Choose or create execution role --> Create a new role with basic lambda permissions --> Create Function




      Once function created, it will redirect into the below looking page.




      Scroll down to section "Function code" and let's paste our python code within the lambda handler function.

      from random import choice
      
      def lambda_handler(event, context):
          # TODO implement
          keyboard_char='abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*_-'
      
          
          
          
          def Gen_Strong_Pass(pass_len,pass_no):
              
              cast_pass_len=int(pass_len)
              cast_pass_no=int(pass_no)
              
              for i in range(pass_no):
                  if i == 0:
                      print('Here are your', cast_pass_no, 'random', cast_pass_len, 'digit tpasswords ! \n')
                  
                  hard_pass=''
                  for j in range(cast_pass_len):
                      hard_pass+=choice(keyboard_char)
                  print(hard_pass+'\n')
      
          Gen_Strong_Pass(event['pass_len'],event['pass_no'])
      

      The top most mandatory function "lambda_handler" can be replaced by anything, and the same must be entered within Handler, inlined to the next text after lambda_function
      as to look like lambda_function.lambda_handler




















      For example, if we want to name our function lambda_handler as my_lambda_handler.

      Handler on the top box must be replaced by lambda_function.my_lambda_handler

      We are ready now lets scroll up to "Configure test events"  and add our events, what is events ? a way to define variables using python dictionary... more is written on top.





      Now let's replace Event name and the key-value pairs by our own inputs.

      Event name : We will name it as "Generate8digit3password" and paste the required key value pairs by our own.


      You might be wondering why this key value pair and where it would be used !

      Events defined within test events can be called within lambda function as
      event['name_of_your_key']  as we defined two key-values as pass_len and pass_no
      let's look into our code and the red boxes will give you the idea, where the event values are called.

























      Once Test event is created, it will be visible under test events drop down.













      Now, we are ready  !

      Go back to your function "Password_Generator" choose from your recent saved test events.
      and click on test.

      Once completed, expand logs to look into log output to see code output as below.





















      Conclusion : We have created a simple password generator using python, deployed it into AWS PASS services named as Lambda.
      We got a run time infrastructure without any setup.

      Tip : You can save more test events like, 9 digit, 16 digit password generator and use it as per your requirements.


      Read more ...

      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 ...
      Related Posts Plugin for WordPress, Blogger...
      Designed By Kunal Saha