Affichage des articles dont le libellé est automation. Afficher tous les articles
Affichage des articles dont le libellé est automation. Afficher tous les articles

vendredi 26 mai 2017

GMAIL - Google Script - auto delete old (junk) mail

Today I discovered the "google scripts" that allow you to run some sophisticated actions on the various "google apps"/"cloud apps". This includes Gmail, Google drive, etc.

Let's start with gmail since I have some needs I could not fit into the pretty basic filters that can be defined directly from the UI.


Context :
* I am able to identify labels are "search" (defined at the time the mail arrives) on my mailbox, that I want to delete after a certain period of time.

For instance, I might be interested in some promotions sent by some companies I have reductions cards with, but after X days, it's of no use and it's only taking precious space in my inbox.

* I do not wish to delete them directly, the "usual" trash with 30 days retention period is fine enought.

* I want to have this run every night.

1. Go to  https://script.google.com

2. Enter this script :

  • set the variable delayDays
  • set the variable mySearch accordingly to your needs.
Version 2017 (old)

function cleanUp() {
  /**
  * @var    delayDays int   : Enter # of days before messages are moved to trash
  * @var    mySearch string : Enter the search as tested in Gmail search bar.
  */
  var delayDays = 30 ;
  var mySearch =  'label:online_store-totoStore OR from:bonsplans@newsletter.travel.com .com OR label:paris-freecycle';
  
  //-- code
  var maxDate = new Date();
  maxDate.setDate(maxDate.getDate()-delayDays);
  var tmp_threads = GmailApp.search(mySearch);
  var threads = [];
  var threads = threads.concat(tmp_threads);

  for (var i = 0; i < threads.length; i++) {
    if (threads[i].getLastMessageDate()
      {
        threads[i].moveToTrash();
      }
  }
}



EDIT 2020 : https://github.com/copolycube/GmailPurgeEmailsMatchingQuery
new version with same features plus :
  • array of simplier queries to find
  • does multiple search instead of 1 massive one
  • concatenates a "avoid deletion", for example to keep "starred" e-mail (by default)


3. Set it up to run every night :
 3.1 : select the 'clock/trigger'.
 3.2 : add the desired triggers on the popup window that will appear.




Other solution (easier)

Use regular Gmail filters triggering deletions, but with search keys like :
older_than:6m

example :  find all promotions older than 1y that haven't been starred

category:promotions older_than:1y -label:starred 



vendredi 19 juin 2015

Ansible vs. Chef vs. Puppet vs. Salt

There are currently various tools to maintain automatically an infrastructure. The four listed below seem to be the main ones.


Ansible is an IT automation tool. It can configure systems, deploy software, and orchestrate more advanced IT tasks such as continuous deployments or zero downtime rolling updates.


·         Chef https://www.chef.io/
“Chef turns infrastructure into code. With Chef, you can automate how you build, deploy, and manage your infrastructure. Your infrastructure becomes as versionable, testable, and repeatable as application code."


·         Puppet https://puppetlabs.com
“Puppet is a configuration management solution that allows you to define the state of your IT infrastructure, and then automatically enforces the desired state. Puppet automates every step of the software delivery process, from provisioning of physical and virtual machines to orchestration and reporting; from early-stage code development through testing, production release and updates.”


·         Salt : http://saltstack.com
“SaltStack takes a new approach to infrastructure management by developing software that is easy enough to get running in seconds, scalable enough to manage tens of thousands of servers, and fast enough to control and communicate with them in milliseconds. SaltStack delivers a dynamic infrastructure communication bus used for orchestration, remote execution, configuration management and much more. The Salt project was launched in 2011 and today is the fastest-growing, most-active infrastructure orchestration and configuration management open source project in the world. The SaltStack community is committed to keeping the Salt project focused, friendly, healthy and open.”




And some comparisions :