Is there a place to get more granular reporting data via API? - reporting

I'm trying to figure out a way to export some of the events I can see in the security dashboard and alert center. The Customer Reports API only gives me the # of mail received per day, and # or spam messages per day, but is more than 24 hrs behind.
I've tried to create an alert in the security alerts center for whenever my domain gets a relevant email, but I just get an email once a minute that says the the threshold was exceeded, and I have to click into the investigation tool to actually get the relevant data.
Is there a place I can request # of phishing emails per hour, or be alerted whenever new phishing emails are found. Or Malware, etc.

The Reports API method UserUsageReport: get allows you to retrieve received spam emails for a certain date by specifying the parameter gmail:num_spam_emails_received
However, if you want to retrieve e.g. the emails from the last hour, there is no prebuilt functionality for this.
You can write a Google Apps Script that would browse your Gmail Inbox for new Spam Emails and set the script on a time-driven trigger
Sample:
function setmeOnHourlyTimer() {
var now = new Date();
var oneHourAgoinSeconds = Math.round(now.getTime()/1000 - 1200 *60);
var query = '"after:'+ oneHourAgoinSeconds +'"';
var spamMessages = Gmail.Users.Messages.list("YOU_EMAIL", {"labelIds": ["SPAM"] , "q": query}).messages;
if (spamMessages.length > 0){
GmailApp.sendEmail("paste your email here", "You have new Spam emails", "You got " + spamMessages.length + " new spam message(s) within the last hour.")
}
}

Related

amavisd-new rule to call external script

We are using amavisd-new (amavisd-new/oldstable,now 1:2.10.1-4) to filter both incomming and outgoing e-mails.
The thing is we receive a log of spam with fake sender from our domain. Since we have less than 100 accounts in our system, is there a plugin that can take the sender address then check it against a valid list of senders?
Thank you a lot.
our system configuration is:
debian stretch
amavisd-new/oldstable,now 1:2.10.1-4
spamassassin/oldstable,oldstable,now 3.4.2-1
If spamassassin checks outgoing email then perhaps a local rule that checks for allowed senders such as:
header LOCAL_WHITELIST From =~ /(me)|(you)|(etc)#mydomain.org/
meta LOCAL_WHITELIST_MATCH ((LOCAL_WHITELIST) =1)
score LOCAL_WHITELIST_MATCH -1.0
meta LOCAL_WHITELIST_MISS ((LOCAL_WHITELIST) =0)
score LOCAL_WHITELIST_MISS 1.0
Unfortunately, I have no idea how to do this just for outgoing email.
It should be straightforward to write a shell script that automatically generates the white list for you and creates the above as a whitelist.cf for spamassassin. That would be cool. Especially if you could get it to run automatically after the creation or deletion of an email account and then amavisd-new reload && service amavisd-new restart.

People API - QUOTA_EXCEEDED / FBS quota limit exceeded

The google people api page says correctly how to authenticate and list 10 example contacts and everything works perfectly:
https://developers.google.com/people/quickstart/python
I can authenticate and list 10 perfectly but I'm having an error when trying to create new contacts.
The api is returning me the following error:
HttpError: <HttpError 429 when requesting https://people.googleapis.com/v1/people:createContact?alt=json returned "Resource has been exhausted (e.g. check quota).". Details: "[{'#type': 'type.googleapis.com/google.rpc.QuotaFailure', 'violations': [{'subject': 'QUOTA_EXCEEDED', 'description': 'FBS quota limit exceeded.'}]}]">
when i click on https://people.googleapis.com/v1/people:createContact?alt=json, i have the following json on page:
{
"error": {
"code": 403,
"message": "The request is missing a valid API key.",
"status": "PERMISSION_DENIED"
}
}
I changed the scopes perfectly, even creating contacts a few months ago.
Out of nowhere everything stopped working and I'm having trouble QUOTA_EXCEEDED and FBS quota limit exceeded
I redid the entire authentication process and even tried to list contacts and without problems, everything works perfectly LESS the creation of contacts
Some observations:
I use via jupyter notebook and I'm also logged in to the email where
I want to create the contacts
I've tried to run in an IDE and the same problem
I've created 26888 contacts this way
This project does not appear on the Google console because I think I
did the entire project through documentation page, and I believe that the quotas have not been exhausted, just because I can see the values ​​correctly. I create on average 1 contact every 3 seconds and 200 contacts per day (maximum)
I would like a lot of help to know why I can't create more contacts, I have a lot of work pending because of that, thanks.
my code to create contacts:
def main():
creds = None
# The file token.pickle stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)
service = build('people', 'v1', credentials=creds)
#----------------creatingc contacts----------------------
print('trying')
for i in df_banco_linhas[:2]:
if i[1] not in df_csv_linhas:
time.sleep(3)
service.people().createContact( body={
"names": [
{
"givenName": i[0]
}
],
"phoneNumbers": [
{
'value': i[1]
}
]
}).execute()
print('create: ' + i[0])
time.sleep(3)
else:
print('NO')
if __name__ == '__main__':
main()
As the problem was only happening when creating contacts, I decided to investigate the limit on the number of contacts and I came across the limit of 25000 in the documentation.
I was forced to create another email to solve the problem and increase my capacity to 50000 contacts (synchronizing two emails).
Their error message denotes that the problem is in the quota limit (requests), when in fact it is limit of contacts by email.
I was getting this same quota limit exceeded error ("FBS quota limit exceeded.") for a different reason. I was supplying values too long for the Organization.jobDescription field.
Perhaps this specific quota limit triggers when some non-rate constraints are violated, like total number of emails or maximum length of fields.
This may not be intended, since that kind of violation doesn't fit the 429 status code, and that limit is not listed in the Quotas section of the API/Service Details page for the People API in the console.

Yammer JSON Feed returning only 20 messages

I am trying to get all the messages from a particular group. I am getting the json feed back. The only problem is, its returning only 20 messages. Is this set as default or something. Is there any way by by which while doing the request, I can specify whether I want all the messages, by default just 20 or even messages posted between the start and the end date?
My RestApi call is:
https://www.yammer.com/api/v1/messages/in_group/[id].json
From Yammer Developer Documentation
<
Autocomplete: 10 requests in 10 seconds.
Messages: 10 requests in 30 seconds.
Notifications: 10 requests in 30 seconds.
All Other Resources: 10 requests in 10 seconds.
These limits are independent e.g. in the same 30 seconds period, you could make 10 message calls and 10 notification calls. The specific rate limits are subject to change but following the guidelines below will ensure that your app is not blocked.>>
I have tried using limit as the parameter to change the number of message more than 20. But it doesnt seem to be working?
Is this problem because of Rate Limit. If not, what's the problem?
Official documentation from Yammers Developer documentation
Messages - Viewing Messages
Endpoints:
1) All public messages in the user’s (whose access token is being used to make the API call henceforth referred to as current user) Yammer network. Corresponds to “All” conversations in the Yammer web interface.
GET https://www.yammer.com/api/v1/messages.json
2) The user’s feed, based on the selection they have made between “Following” and “Top” conversations.
GET https://www.yammer.com/api/v1/messages/my_feed.json
3) The algorithmic feed for the user that corresponds to “Top” conversations, which is what the vast majority of users will see in the Yammer web interface.
GET https://www.yammer.com/api/v1/messages/algo.json
4) The “Following” feed which is conversations involving people, groups and topics that the user is following.
GET https://www.yammer.com/api/v1/messages/following.json
5) All messages sent by the user. Alias for /api/v1/messages/from_user/logged-in_user_id.format.
GET https://www.yammer.com/api/v1/messages/sent.json
6) Private messages received by the user.
GET https://www.yammer.com/api/v1/messages/private.json
7) All messages received by the user.
GET https://www.yammer.com/api/v1/messages/received.json
Parameters:
The messages API endpoints return a similar structure and support the following query parameters:
older_than - Returns messages older than the message ID specified as a numeric string. This is useful for paginating messages. For example, if you’re currently viewing 20 messages and the oldest is number 2912, you could append “?older_than=2912″ to your request to get the 20 messages prior to those you’re seeing.
newer_than - Returns messages newer than the message ID specified as a numeric string. This should be used when polling for new messages. If you’re looking at messages, and the most recent message returned is 3516, you can make a request with the parameter “?newer_than=3516″ to ensure that you do not get duplicate copies of messages already on your page.
threaded=[true | extended] - threaded=true will only return the first message in each thread. This parameter is intended for apps which display message threads collapsed. threaded=extended will return the thread starter messages in order of most recently active as well as the two most recent messages, as they are viewed in the default view on the Yammer web interface.
limit - Return only the specified number of messages. Works for threaded=true and threaded=extended.
Noted the limit parameter that you can set on your GET request - so based on this documentation if it is correct (I'm not a Yammer Developer but I do use it) you should be able to do
https://www.yammer.com/api/v1/messages.json?limit=50
That is in theory but reading through the documentation there is a section on Search that has
page - Only 20 results of each type will be returned for each page, but a total count is returned with each query. page=1 (the default) will return items 1-20, page=2 will return items 21-30, etc.
Which says to me they are limited to 20 results returned.
UPDATE
After testing this with https://www.yammer.com/api/v1/messages.json?limit=50 and it not returning 50 messages but doing https://www.yammer.com/api/v1/messages.json?limit=5 will return only 5 messages I would say that Yammer restrict the number of messages to 20 Also after reading through the documents a bit more I read
For example, if you’re currently viewing 20 messages and the oldest is number 2912, you could append “?older_than=2912″ to your request to get the 20 messages prior to those you’re seeing"
This says to me that they will only return a max of 20. So I think you are stuck with 20 messages at a time.
Hope this helps.
You need to use Parameters:
The messages API endpoints return a similar structure and support the following query parameters:
older_than - Returns messages older than the message ID specified as a numeric string. This is useful for paginating messages. For example, if you’re currently viewing 20 messages and the oldest is number 2912, you could append “?older_than=2912″ to your request to get the 20 messages prior to those you’re seeing.
newer_than - Returns messages newer than the message ID specified as a numeric string. This should be used when polling for new messages. If you’re looking at messages, and the most recent message returned is 3516, you can make a request with the parameter “?newer_than=3516″ to ensure that you do not get duplicate copies of messages already on your page.
threaded=[true | extended] - threaded=true will only return the first message in each thread. This parameter is intended for apps which display message threads collapsed. threaded=extended will return the thread starter messages in order of most recently active as well as the two most recent messages, as they are viewed in the default view on the Yammer web interface.
limit - Return only the specified number of messages. Works for threaded=true and threaded=extended.
Example : GET https://www.yammer.com/api/v1/messages.json?older_than=2912
while older can be ID of message number 20 and so on you can get 20 by 20
I solved by requesting subsequent pages in a recursive manner.
You can simply increase the page parameter until the response is empty, or update the older_than parameter until the property meta.older_available is false.

Quickbooks POS AddOn Sales Reciept TxnID

I am creating my first AddOn using Quickbooks POS AddOn Dev Kit v10.
I have created a button in the receipts side buttons panel.
Now what I want is the current sales receipt.
For that, what I am trying to do is to get TxnID and query request processor, with that TxnID to get the whole receipt.
I have managed to get information like Qty, Desc1, ItemNum etc. I have also get the Receipt Schema.
https://idnforums.intuit.com/messageview.aspx?catid=49&threadid=16722
From above url, it says DocSID is the TxnID, but I cant get the field value through DocSID.
How can I get the TxnID or is there a better way to do it for getting the current sales reciept?
Thanks in Advance.
After working on it for 2-3 days, I came to know that TxnID will be created after the sales receipt is saved in QB POS through the IPOSService ProcessQBPOSXMLRequest method.
ProcessQBPOSXMLRequest only takes and repond in XML format. I created the receipt request in XML and send it ProcessQBPOSXMLRequest for processing.
I was avoding creatingg the XML request, since it was a long and tedious work, but I did similar work while creating another application with QBPOS SDK v3, with QBPOSFC3 library. I copied the code and add reference to QBPOSFC3.dll, and created xml from IMsgSetRequest interface which send request to POS request processor and convert the request in XML format.

How can I route SMSes using Twilio, based on a schedule?

I send SMS alerts to my mobile phone using Twilio; I would like to route this to a different number based on a schedule / rota? ie I am in the US, so during my day I would like to get alerts, and then during the UK's day I would like someone else?
Any ideas?
Thanks
You can just configure the sending address based on the current date and time. In Python this would look something like this:
from datetime import datetime
curr_time = datetime.utcnow()
# roughly, London working hours
if 8 < curr_time.hour <= 17:
recipient = "+44XXXXXXXXXXX"
else:
recipient = "+1XXXXXXXXXXXX"
send_sms_message(from=twilio_number, to=recipient, body=body)
Without knowing more about how you are sending the messages, or how you are generating alerts, it's difficult to provide a more nuanced answer.

Resources