Tuesday, April 23, 2019

openwrt strongswan config for android and ios using native vpn client


/etc/ipsec.config

 conn ios
              keyexchange=ikev1
              authby=xauthrsasig
              xauth=server
              left=%any
              leftsubnet=0.0.0.0/0
              leftfirewall=yes
              leftcert=serverCert.pem
              right=%any
              rightsubnet=192.168.1.0/24
              rightsourceip=%dhcp
              rightcert=clientCert.pem
              forceencaps=yes
              auto=add
conn android
 keyexchange=ikev2
 left=%any
 leftauth=pubkey
 leftcert=serverCert.pem
 leftid=yourdomain.dyndns.org
 leftsubnet=0.0.0.0/0,::/0
 right=%any
 rightsubnet=192.168.1.0/24
 rightsourceip=%dhcp
 rightauth=pubkey
 rightcert=androidCert.pem
 auto=add

Tuesday, April 9, 2019

Extending the angular and react single page application with graph api to customer web api

The original article are published here:

https://docs.microsoft.com/en-us/graph/tutorials/angular
https://docs.microsoft.com/en-us/graph/tutorials/react

to make it work with my own web api, I have to make considerable adjustment:

in the react version, there is a need to give the tenant specific authority URL.

class App extends Component {
constructor(props) {
super(props);

this.userAgentApplication = new UserAgentApplication(config.appId,
"https://login.microsoftonline.com/{tentan}", null);

this is how we call the web api:

async componentDidMount() {
try {
// Get the user's access token
var accessToken = await window.msal.acquireTokenSilent(config.scopes2);

var timesheets = await api.get(accessToken);
// Update the array of events in state
this.setState({timesheets: timesheets});


The angular version:

export class TimesheetService {

accessToken: string;

constructor(private authService: AuthService,
private alertsService: AlertsService,
private http: HttpClient
) {
//move the following two line to login method within authService and save token in cache.
//this.authService.getAccessToken(OAuthSettings.scopes2).then(data => {
//this.accessToken = data;
this.accessToken = sessionStorage.getItem('access_token');

});
}
getTimeSheets():Observable<TimeSheet[]> {
var header = {headers: new HttpHeaders()
.set('Authorization', 'Bearer ' + this.accessToken)
}
return this.http.get<Array<TimeSheet>>('https://localhost:44301/api/TimeSheets?WeekEnding=2018-10-01',header);
}


export class TimesheetComponent implements OnInit {

private timesheets: TimeSheet[];

constructor(private timesheetService: TimesheetService) { }

ngOnInit() {
this.getTimeSheets();
}
getTimeSheets() {
this.timesheetService.getTimeSheets().subscribe(data => {
this.timesheets = data;
});
}


Most importantly , you need to specific the scope for the web api when acquiring the token, a sample config is as below:

export const OAuthSettings = {
appId: 'xxxxx-xxxx-4edxxxx9-xxxx-xxxxxx',
scopes: [
"user.read",
"calendars.read"
],
scopes2: [
"https://{tenant}}.onmicrosoft.com/webapi/access_as_user"
]

};

Finally you also need to sort out CORS issue.

Tuesday, March 26, 2019

"Something is wrong with the numpy installation. While importing we detected an older version of numpy" error on azure databricks

"Something is wrong with the numpy installation. While importing we detected an older version of numpy"

I was doing the lab below and experienced the issue today.

https://cloudworkshop.blob.core.windows.net/cognitive-deep-learning/Hands-on%20lab/HOL%20step-by%20step%20-%20Cognitive%20services%20and%20deep%20learning.html

the problem seems to be related to azureml-sdk[databricks] because if I uninstall it some part of code can still run.
after spending quite some time scratching my hair, I looked up the azureml-sdk release page and found out that a new version 1.0.21 released just today (26 March 2019), I uninstall the default version and installed the prior version by using the format azureml-sdk[databricks]==1.0.18.1

alternatively if you choose runtime version 5.2 when creating the cluster then the problem doesn't occur.

Monday, February 18, 2019

Dax: currency conversion with date range

if you have daily exchange rate, the post at https://www.kasperonbi.com/currency-conversion-in-dax-for-power-bi-and-ssas/ shows a nice solution, however if you are like me where exchange rates are only updated periodically hence come with a start and end date then you need a difference solution.

with a small change to the above, I came up with an alternative solution as below:




Sales (in reporting currency) := if(HASONEVALUE(ReportCurrency[ReportCurrency]),
SUMX(FactSales,FactSales[Sales]*CALCULATE(MIN(FactExchangeRate[Factor]),
FILTER(FactExchangeRate,
AND(FactExchangeRate[FromDate]<=FactSales[Date],FactExchangeRate[ToDate]> FactSales[Date])
)
)
)
)

YTD Sales (year to date) :=
SUMX(
CALCULATETABLE(FactSales,ALL(FactSales[Date]),DATESYTD(DATE[date]))
FactSales[Sales]*CALCULATE(MIN(FactExchangeRate[Factor]),
FILTER(FactExchangeRate,
AND(FactExchangeRate[FromDate]<=FactSales[Date],FactExchangeRate[ToDate]> FactSales[Date])
)
)


)


LTD Sales (life to date) :=


SUMX(
CALCULATETABLE(FactSales,ALL(FactSales[Date]),
FILTER(ALL(DATE),DATE[Date] <= MAX(DATE[date]))
)
FactSales[Sales]*CALCULATE(MIN(FactExchangeRate[Factor]),
FILTER(FactExchangeRate,
AND(FactExchangeRate[FromDate]<=FactSales[Date],FactExchangeRate[ToDate]> FactSales[Date])
)
)

)

The above formula are quite resource intensive though, hence if you are working on a very large dataset, it is probably better to have them pre-calculated

Thursday, November 1, 2018

VirtualBox SQL FCI - Given Network Name Is Unusable

VirtualBox SQL FCI - Given Network Name Is Unusable

The other day I needed to test some HADR requirements on my local machine so using VirtualBox, I created a 2 server Windows 2012 R2 failover cluster with shared storage provided by FreeNAS and a domain controller. All was good at the windows level so I proceeded to install a SQL cluster next but part way through the setup of creating the SQL cluster, I was hit with this error message:
The given network name is unusable because there was a failure trying to determine if the network name is valid for use by the clustered SQL instance due to the following error: 'The network address is invalid.'
I couldn't see anything obvious at first. I was using the domain admin account so nowt wrong with permissions. All VM's were up, IP was configured OK, cluster was OK and there nothing of use from the setup log file. So drawing a blank next I hit Google. I eventually came across a VMware based StackExchange post suggesting to remove the Guest additions but one of the comments said that this worked for VirtualBox as well. I was a bit sceptical at first, but I uninstalled the additions software from the guest OS and after rebooting the SQL setup continued perfectly!.. No idea what or why the additions where doing what they were, but problem solved with a relatively issue tweak to the OS. I only had the issue when creating the cluster with the first node. The second node was fine being added to the existing cluster with the guest additions software still being installed. Bizarre, anyway, I hope this helps someone with the same issue.
Enjoy!...

Monday, October 29, 2018

High availability for NFS on Azure VMs on Ubuntu 18.04 LTS

I was trying to follow this guide however realised that I do not have SUSE enterprise license to play with, generally I am more familiar with Red Hat hower I decided to give ubuntu a go this time.

https://docs.microsoft.com/en-us/azure/virtual-machines/workloads/sap/high-availability-guide-suse-nfs 

a few important adjustment need to be done to make this working:

Installation: 

sudo apt-get install -y drbd8-utils
sudo apt-get install nfs-kernel-server
sudo apt install pacemaker corosync fence-agents
sudo apt install crmsh
sudo apt install netcat

#I can't get azure fencing agent working so I used sbd fencing
#sudo pip install azure
#sudo pip install azure-common
#sudo pip install azure-mgmt-compute

sudo apt install sbd

adjust nfs v4 grace timeout:

sudo vi /etc/default/nfs-kernel-server
Add:  NFSD_V4_GRACE=10

full configuration for pacemaker: 

george@nfs-1:~$ sudo crm configure show
node 1: nfs-0
node 2: nfs-1
primitive drbd_NW1_nfs ocf:linbit:drbd \
        params drbd_resource=NW1-nfs \
        op monitor interval=15 role=Master \
        op monitor interval=30 role=Slave
primitive exportfs_NW1 exportfs \
        params directory="/srv/nfs/NW1" options="rw,no_root_squash,crossmnt" clientspec="*" fsid=1 wait_for_leasetime_on_stop=true \
        op monitor interval=30s \
        op start interval=0 timeout=40 \
        op stop interval=0 timeout=120 \
        meta target-role=Started
primitive fs_NW1_sapmnt Filesystem \
        params device="/dev/drbd0" directory="/srv/nfs/NW1" fstype=ext4 \
        op monitor interval=10s
primitive nc_NW1_nfs anything \
        params binfile="/bin/netcat" cmdline_options="-l -k 61000"  \
        op monitor timeout=20s interval=10 depth=0
primitive nfsserver lsb:nfs-kernel-server \
        op monitor interval=30s
primitive stonith-sbd stonith:external/sbd \
        params pcmk_delay_max=15 \
        op monitor interval=15 timeout=15
primitive vip_NW1_nfs IPaddr2 \
        params ip=10.0.1.100 cidr_netmask=24 \
        op monitor interval=10 timeout=20
group g-NW1_nfs nfsserver vip_NW1_nfs fs_NW1_sapmnt exportfs_NW1 \
        meta target-role=Started
ms ms-drbd_NW1_nfs drbd_NW1_nfs \
        meta master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true interleave=true
colocation col-NW1_nfs_on_drbd inf: g-NW1_nfs ms-drbd_NW1_nfs:Master
order o-NW1_drbd_before_nfs inf: ms-drbd_NW1_nfs:promote g-NW1_nfs:start
property cib-bootstrap-options: \
        have-watchdog=false \
        dc-version=1.1.18-2b07d5c5a9 \
        cluster-infrastructure=corosync \
        cluster-name=NW1-nfs \
        stonith-enabled=true \
        no-quorum-policy=ignore \
        maintenance-mode=false \
        stonith-timeout=144
rsc_defaults rsc-options: \
        resource-stickiness=200




Disable Microsoft Defender for Cloud for Visual Studio Subscription (MSDN)

I use a visual studio pro subscription which comes with $150 azure cloud credit, for some reason Microsoft Defender for Cloud was turned on ...